本文整理汇总了PHP中Doctrine\DBAL\Migrations\Configuration\Configuration::getMigrationsTableName方法的典型用法代码示例。如果您正苦于以下问题:PHP Configuration::getMigrationsTableName方法的具体用法?PHP Configuration::getMigrationsTableName怎么用?PHP Configuration::getMigrationsTableName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\DBAL\Migrations\Configuration\Configuration
的用法示例。
在下文中一共展示了Configuration::getMigrationsTableName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMigrationsInfos
public function getMigrationsInfos()
{
$numExecutedUnavailableMigrations = count($this->executedUnavailableMigrations);
$numNewMigrations = count(array_diff($this->availableMigrations, $this->executedMigrations));
$infos = ['Name' => $this->configuration->getName() ? $this->configuration->getName() : 'Doctrine Database Migrations', 'Database Driver' => $this->configuration->getConnection()->getDriver()->getName(), 'Database Name' => $this->configuration->getConnection()->getDatabase(), 'Configuration Source' => $this->configuration instanceof AbstractFileConfiguration ? $this->configuration->getFile() : 'manually configured', 'Version Table Name' => $this->configuration->getMigrationsTableName(), 'Version Column Name' => $this->configuration->getMigrationsColumnName(), 'Migrations Namespace' => $this->configuration->getMigrationsNamespace(), 'Migrations Directory' => $this->configuration->getMigrationsDirectory(), 'Previous Version' => $this->getFormattedVersionAlias('prev'), 'Current Version' => $this->getFormattedVersionAlias('current'), 'Next Version' => $this->getFormattedVersionAlias('next'), 'Latest Version' => $this->getFormattedVersionAlias('latest'), 'Executed Migrations' => count($this->executedMigrations), 'Executed Unavailable Migrations' => $numExecutedUnavailableMigrations, 'Available Migrations' => count($this->availableMigrations), 'New Migrations' => $numNewMigrations];
return $infos;
}
示例2: writeSqlFile
/**
* Write a migration SQL file to the given path
*
* @param string $path The path to write the migration SQL file.
* @param string $to The version to migrate to.
*
* @return boolean $written
*/
public function writeSqlFile($path, $to = null)
{
$sql = $this->getSql($to);
$from = $this->configuration->getCurrentVersion();
if ($to === null) {
$to = $this->configuration->getLatestVersion();
}
$direction = $from > $to ? 'down' : 'up';
$this->outputWriter->write(sprintf("# Migrating from %s to %s\n", $from, $to));
$sqlWriter = new SqlFileWriter($this->configuration->getMigrationsTableName(), $path, $this->outputWriter);
return $sqlWriter->write($sql, $direction);
}
示例3: writeSqlFile
/**
* Write a migration SQL file to the given path
*
* @param string $path The path to write the migration SQL file.
* @param string $to The version to migrate to.
*
* @return boolean $written
*/
public function writeSqlFile($path, $to = null)
{
$sql = $this->getSql($to);
$from = $this->configuration->getCurrentVersion();
if ($to === null) {
$to = $this->configuration->getLatestVersion();
}
$direction = $from > $to ? 'down' : 'up';
$string = sprintf("# Doctrine Migration File Generated on %s\n", date('Y-m-d H:i:s'));
$string .= sprintf("# Migrating from %s to %s\n", $from, $to);
foreach ($sql as $version => $queries) {
$string .= "\n# Version " . $version . "\n";
foreach ($queries as $query) {
$string .= $query . ";\n";
}
if ($direction == "down") {
$string .= "DELETE FROM " . $this->configuration->getMigrationsTableName() . " WHERE version = '" . $version . "';\n";
} else {
$string .= "INSERT INTO " . $this->configuration->getMigrationsTableName() . " (version) VALUES ('" . $version . "');\n";
}
}
if (is_dir($path)) {
$path = realpath($path);
$path = $path . '/doctrine_migration_' . date('YmdHis') . '.sql';
}
$this->outputWriter->write("\n" . sprintf('Writing migration file to "<info>%s</info>"', $path));
return file_put_contents($path, $string);
}
示例4: writeSqlFile
/**
* Write a migration SQL file to the given path
*
* @param string $path The path to write the migration SQL file.
* @param string $direction The direction to execute.
*
* @return boolean $written
*/
public function writeSqlFile($path, $direction = 'up')
{
$queries = $this->execute($direction, true);
$this->outputWriter->write("\n# Version " . $this->version . "\n");
$sqlQueries = [$this->version => $queries];
$sqlWriter = new SqlFileWriter($this->configuration->getMigrationsTableName(), $path, $this->outputWriter);
return $sqlWriter->write($sqlQueries, $direction);
}
示例5: _buildCodeFromSql
private function _buildCodeFromSql(Configuration $configuration, array $sql)
{
$code = array();
foreach ($sql as $query) {
if (strpos($query, $configuration->getMigrationsTableName()) !== false) {
continue;
}
$code[] = "\$this->_addSql('" . $query . "');";
}
return implode("\n", $code);
}
示例6: writeSqlFile
/**
* Write a migration SQL file to the given path
*
* @param string $path The path to write the migration SQL file.
* @param string $direction The direction to execute.
*
* @return boolean $written
*/
public function writeSqlFile($path, $direction = self::DIRECTION_UP)
{
$queries = $this->execute($direction, true);
if (!empty($this->params)) {
throw MigrationException::migrationNotConvertibleToSql($this->class);
}
$this->outputWriter->write("\n-- Version " . $this->version . "\n");
$sqlQueries = [$this->version => $queries];
$sqlWriter = new SqlFileWriter($this->configuration->getMigrationsColumnName(), $this->configuration->getMigrationsTableName(), $path, $this->outputWriter);
return $sqlWriter->write($sqlQueries, $direction);
}
示例7: buildCodeFromSql
private function buildCodeFromSql(Configuration $configuration, array $sql)
{
$currentPlatform = $configuration->getConnection()->getDatabasePlatform()->getName();
$code = array("\$this->abortIf(\$this->connection->getDatabasePlatform()->getName() != \"{$currentPlatform}\", \"Migration can only be executed safely on '{$currentPlatform}'.\");", "");
foreach ($sql as $query) {
if (strpos($query, $configuration->getMigrationsTableName()) !== false) {
continue;
}
$code[] = "\$this->addSql(\"{$query}\");";
}
return implode("\n", $code);
}
示例8: configureMigrations
public static function configureMigrations(ContainerInterface $container, Configuration $configuration)
{
if (!$configuration->getMigrationsDirectory()) {
$dir = $container->getParameter('doctrine_migrations.dir_name');
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
$configuration->setMigrationsDirectory($dir);
} else {
$dir = $configuration->getMigrationsDirectory();
// class Kernel has method getKernelParameters with some of the important path parameters
$pathPlaceholderArray = array('kernel.root_dir', 'kernel.cache_dir', 'kernel.logs_dir');
foreach ($pathPlaceholderArray as $pathPlaceholder) {
if ($container->hasParameter($pathPlaceholder) && preg_match('/\\%' . $pathPlaceholder . '\\%/', $dir)) {
$dir = str_replace('%' . $pathPlaceholder . '%', $container->getParameter($pathPlaceholder), $dir);
}
}
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
$configuration->setMigrationsDirectory($dir);
}
if (!$configuration->getMigrationsNamespace()) {
$configuration->setMigrationsNamespace($container->getParameter('doctrine_migrations.namespace'));
}
if (!$configuration->getName()) {
$configuration->setName($container->getParameter('doctrine_migrations.name'));
}
// For backward compatibility, need use a table from parameters for overwrite the default configuration
if (!$configuration->getMigrationsTableName() || !$configuration instanceof AbstractFileConfiguration) {
$configuration->setMigrationsTableName($container->getParameter('doctrine_migrations.table_name'));
}
// Migrations is not register from configuration loader
if (!$configuration instanceof AbstractFileConfiguration) {
$configuration->registerMigrationsFromDirectory($configuration->getMigrationsDirectory());
}
if ($container->hasParameter('doctrine_migrations.organize_migrations')) {
$organizeMigrations = $container->getParameter('doctrine_migrations.organize_migrations');
switch ($organizeMigrations) {
case Configuration::VERSIONS_ORGANIZATION_BY_YEAR:
$configuration->setMigrationsAreOrganizedByYear(true);
break;
case Configuration::VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH:
$configuration->setMigrationsAreOrganizedByYearAndMonth(true);
break;
case false:
break;
default:
throw new InvalidConfigurationException('Unrecognized option "' . $organizeMigrations . '" under "organize_migrations"');
}
}
self::injectContainerToMigrations($container, $configuration->getMigrations());
}
示例9: getMigrationsInfos
public function getMigrationsInfos()
{
$formattedVersions = [];
foreach (['prev', 'current', 'next', 'latest'] as $alias) {
$version = $this->configuration->resolveVersionAlias($alias);
if ($version === null) {
if ($alias == 'next') {
$formattedVersions[$alias] = 'Already at latest version';
} elseif ($alias == 'prev') {
$formattedVersions[$alias] = 'Already at first version';
}
} elseif ($version === '0') {
$formattedVersions[$alias] = '<comment>0</comment>';
} else {
$formattedVersions[$alias] = $this->configuration->getDateTime($version) . ' (<comment>' . $version . '</comment>)';
}
}
$numExecutedUnavailableMigrations = count($this->executedUnavailableMigrations);
$numNewMigrations = count(array_diff($this->availableMigrations, $this->executedMigrations));
$infos = ['Name' => $this->configuration->getName() ? $this->configuration->getName() : 'Doctrine Database Migrations', 'Database Driver' => $this->configuration->getConnection()->getDriver()->getName(), 'Database Name' => $this->configuration->getConnection()->getDatabase(), 'Configuration Source' => $this->configuration instanceof AbstractFileConfiguration ? $this->configuration->getFile() : 'manually configured', 'Version Table Name' => $this->configuration->getMigrationsTableName(), 'Version Column Name' => $this->configuration->getMigrationsColumnName(), 'Migrations Namespace' => $this->configuration->getMigrationsNamespace(), 'Migrations Directory' => $this->configuration->getMigrationsDirectory(), 'Previous Version' => $formattedVersions['prev'], 'Current Version' => $formattedVersions['current'], 'Next Version' => $formattedVersions['next'], 'Latest Version' => $formattedVersions['latest'], 'Executed Migrations' => count($this->executedMigrations), 'Executed Unavailable Migrations' => $numExecutedUnavailableMigrations, 'Available Migrations' => count($this->availableMigrations), 'New Migrations' => $numNewMigrations];
return $infos;
}
示例10: writeSqlFile
/**
* Write a migration SQL file to the given path
*
* @param string $path The path to write the migration SQL file.
* @param string $direction The direction to execute.
*
* @return boolean $written
*/
public function writeSqlFile($path, $direction = 'up')
{
$queries = $this->execute($direction, true);
$string = sprintf("# Doctrine Migration File Generated on %s\n", date('Y-m-d H:i:s'));
$string .= "\n# Version " . $this->version . "\n";
foreach ($queries as $query) {
$string .= $query . ";\n";
}
if ($direction == "down") {
$string .= "DELETE FROM " . $this->configuration->getMigrationsTableName() . " WHERE version = '" . $this->version . "';\n";
} else {
$string .= "INSERT INTO " . $this->configuration->getMigrationsTableName() . " (version) VALUES ('" . $this->version . "');\n";
}
if (is_dir($path)) {
$path = realpath($path);
$path = $path . '/doctrine_migration_' . date('YmdHis') . '.sql';
}
$this->outputWriter->write("\n" . sprintf('Writing migration file to "<info>%s</info>"', $path));
return file_put_contents($path, $string);
}
示例11: configureMigrations
public static function configureMigrations(ContainerInterface $container, Configuration $configuration)
{
if (!$configuration->getMigrationsDirectory()) {
$dir = $container->getParameter('doctrine_migrations.dir_name');
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
$configuration->setMigrationsDirectory($dir);
} else {
$dir = $configuration->getMigrationsDirectory();
// class Kernel has method getKernelParameters with some of the important path parameters
$pathPlaceholderArray = array('kernel.root_dir', 'kernel.cache_dir', 'kernel.logs_dir');
foreach ($pathPlaceholderArray as $pathPlaceholder) {
if ($container->hasParameter($pathPlaceholder) && preg_match('/\\%' . $pathPlaceholder . '\\%/', $dir)) {
$dir = str_replace('%' . $pathPlaceholder . '%', $container->getParameter($pathPlaceholder), $dir);
}
}
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
$configuration->setMigrationsDirectory($dir);
}
if (!$configuration->getMigrationsNamespace()) {
$configuration->setMigrationsNamespace($container->getParameter('doctrine_migrations.namespace'));
}
if (!$configuration->getName()) {
$configuration->setName($container->getParameter('doctrine_migrations.name'));
}
// For backward compatibility, need use a table from parameters for overwrite the default configuration
if (!$configuration->getMigrationsTableName() || !$configuration instanceof AbstractFileConfiguration) {
$configuration->setMigrationsTableName($container->getParameter('doctrine_migrations.table_name'));
}
// Migrations is not register from configuration loader
if (!$configuration instanceof AbstractFileConfiguration) {
$configuration->registerMigrationsFromDirectory($configuration->getMigrationsDirectory());
}
self::injectContainerToMigrations($container, $configuration->getMigrations());
}
示例12: buildCodeFromSql
/**
* Returns PHP code for a migration file that "executes" the given
* array of SQL statements.
*
* @param \Doctrine\DBAL\Migrations\Configuration\Configuration $configuration
* @param array $sql
* @return string
*/
protected function buildCodeFromSql(\Doctrine\DBAL\Migrations\Configuration\Configuration $configuration, array $sql)
{
$currentPlatform = $configuration->getConnection()->getDatabasePlatform()->getName();
$code = array('$this->abortIf($this->connection->getDatabasePlatform()->getName() != "' . $currentPlatform . '");', '');
foreach ($sql as $query) {
if (strpos($query, $configuration->getMigrationsTableName()) !== false) {
continue;
}
$code[] = '$this->addSql("' . $query . '");';
}
return implode("\n", $code);
}
示例13: buildCodeFromSql
private function buildCodeFromSql(Configuration $configuration, array $sql, $formatted = false, $lineLength = 120)
{
$currentPlatform = $configuration->getConnection()->getDatabasePlatform()->getName();
$code = [];
foreach ($sql as $query) {
if (stripos($query, $configuration->getMigrationsTableName()) !== false) {
continue;
}
if ($formatted) {
if (!class_exists('\\SqlFormatter')) {
throw new \InvalidArgumentException('The "--formatted" option can only be used if the sql formatter is installed.' . 'Please run "composer require jdorn/sql-formatter".');
}
$maxLength = $lineLength - 18 - 8;
// max - php code length - indentation
if (strlen($query) > $maxLength) {
$query = \SqlFormatter::format($query, false);
}
}
$code[] = sprintf("\$this->addSql(%s);", var_export($query, true));
}
if (!empty($code)) {
array_unshift($code, sprintf("\$this->abortIf(\$this->connection->getDatabasePlatform()->getName() !== %s, %s);", var_export($currentPlatform, true), var_export(sprintf("Migration can only be executed safely on '%s'.", $currentPlatform), true)), "");
}
return implode("\n", $code);
}
示例14: buildCodeFromSql
/**
* Returns PHP code for a migration file that "executes" the given
* array of SQL statements.
*
* @param \Doctrine\DBAL\Migrations\Configuration\Configuration $configuration
* @param array $sql
* @return string
*/
protected function buildCodeFromSql(\Doctrine\DBAL\Migrations\Configuration\Configuration $configuration, array $sql)
{
$currentPlatform = $configuration->getConnection()->getDatabasePlatform()->getName();
$code = array("\$this->abortIf(\$this->connection->getDatabasePlatform()->getName() != \"{$currentPlatform}\");", "");
foreach ($sql as $query) {
if (strpos($query, $configuration->getMigrationsTableName()) !== FALSE) {
continue;
}
$code[] = "\$this->addSql(\"{$query}\");";
}
return implode("\n", $code);
}
示例15: buildCodeFromSql
private function buildCodeFromSql(Configuration $configuration, array $sql)
{
$currentPlatform = $configuration->getConnection()->getDatabasePlatform()->getName();
$code = array();
foreach ($sql as $query) {
if (stripos($query, $configuration->getMigrationsTableName()) !== false) {
continue;
}
$code[] = sprintf("\$this->addSql(%s);", var_export($query, true));
}
if ($code) {
array_unshift($code, sprintf("\$this->abortIf(\$this->connection->getDatabasePlatform()->getName() != %s, %s);", var_export($currentPlatform, true), var_export(sprintf("Migration can only be executed safely on '%s'.", $currentPlatform), true)), "");
}
return implode("\n", $code);
}