Пример #1
0
 /**
  * Execute the console command.
  *
  * @param ConfigurationProvider  $provider
  * @param ManagerRegistry        $registry
  * @param SqlBuilder             $builder
  * @param MigrationFileGenerator $generator
  */
 public function fire(ConfigurationProvider $provider, ManagerRegistry $registry, SqlBuilder $builder, MigrationFileGenerator $generator)
 {
     $configuration = $provider->getForConnection($this->option('connection'));
     $em = $registry->getManager($this->option('connection'));
     $connection = $configuration->getConnection();
     // Overrule the filter
     if ($filterExpr = $this->option('filter-expression')) {
         $connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpr);
     }
     $fromSchema = $connection->getSchemaManager()->createSchema();
     $toSchema = $this->getSchemaProvider($em)->createSchema();
     // Drop tables which don't suffice to the filter regex
     if ($filterExpr = $connection->getConfiguration()->getFilterSchemaAssetsExpression()) {
         foreach ($toSchema->getTables() as $table) {
             $tableName = $table->getName();
             if (!preg_match($filterExpr, $this->resolveTableName($tableName))) {
                 $toSchema->dropTable($tableName);
             }
         }
     }
     $up = $builder->up($configuration, $fromSchema, $toSchema);
     $down = $builder->down($configuration, $fromSchema, $toSchema);
     if (!$up && !$down) {
         return $this->error('No changes detected in your mapping information.');
     }
     $path = $generator->generate($configuration, false, false, $up, $down);
     $this->line(sprintf('Generated new migration class to "<info>%s</info>" from schema differences.', $path));
 }
 /**
  * Execute the console command.
  *
  * @param ConfigurationProvider $provider
  */
 public function fire(ConfigurationProvider $provider)
 {
     $configuration = $provider->getForConnection($this->option('connection'));
     $version = $this->argument('version') ?: $configuration->getCurrentVersion();
     if ($version == 0) {
         return $this->error('No migrations to be rollbacked');
     }
     $this->call('doctrine:migrations:execute', ['version' => $version, '--connection' => $this->option('connection'), '--down' => true]);
 }
Пример #3
0
 /**
  * Execute the console command.
  *
  * @param ConfigurationProvider $provider
  */
 public function fire(ConfigurationProvider $provider)
 {
     $configuration = $provider->getForConnection($this->option('connection'));
     $connection = $configuration->getConnection();
     $schema = $connection->getSchemaManager();
     $connection->query(sprintf('SET FOREIGN_KEY_CHECKS = 0;'));
     $tables = $schema->listTableNames();
     foreach ($tables as $table) {
         $schema->dropTable($table);
     }
     $connection->query(sprintf('SET FOREIGN_KEY_CHECKS = 1;'));
     $this->info('Database was reset');
 }
 /**
  * Execute the console command.
  *
  * @param ConfigurationProvider $provider
  */
 public function fire(ConfigurationProvider $provider)
 {
     $this->configuration = $provider->getForConnection($this->option('connection'));
     if (!$this->option('add') && !$this->option('delete')) {
         return $this->error('You must specify whether you want to --add or --delete the specified version.');
     }
     $this->markMigrated = (bool) $this->option('add');
     $question = 'WARNING! You are about to add, delete or synchronize migration versions from the version table that could result in data lost. Are you sure you wish to continue? (y/n)';
     if ($this->confirm($question)) {
         $this->markVersions();
     } else {
         $this->error('Migration cancelled!');
     }
 }
 /**
  * Execute the console command.
  *
  * @param ConfigurationProvider $provider
  * @param Migrator              $migrator
  */
 public function fire(ConfigurationProvider $provider, Migrator $migrator)
 {
     if (!$this->confirmToProceed()) {
         return;
     }
     $configuration = $provider->getForConnection($this->option('connection'));
     $version = $this->argument('version');
     $direction = $this->option('down') ? 'down' : 'up';
     $version = $configuration->getVersion($version);
     if ($path = $this->option('write-sql')) {
         $migrator->executeToFile($version, $direction, $path);
     } else {
         $migrator->execute($version, $direction, $this->option('dry-run'), $this->option('query-time'));
     }
     foreach ($migrator->getNotes() as $note) {
         $this->line($note);
     }
 }
 /**
  * Execute the console command.
  *
  * @param ConfigurationProvider $provider
  */
 public function fire(ConfigurationProvider $provider)
 {
     $configuration = $provider->getForConnection($this->option('connection'));
     $formattedVersions = [];
     foreach (['prev', 'current', 'next', 'latest'] as $alias) {
         $version = $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] = $configuration->getDateTime($version) . ' (<comment>' . $version . '</comment>)';
         }
     }
     $executedMigrations = $configuration->getMigratedVersions();
     $availableMigrations = $configuration->getAvailableVersions();
     $executedUnavailableMigrations = array_diff($executedMigrations, $availableMigrations);
     $numExecutedUnavailableMigrations = count($executedUnavailableMigrations);
     $newMigrations = count(array_diff($availableMigrations, $executedMigrations));
     $this->line("\n <info>==</info> Configuration\n");
     $info = ['Database Driver' => $configuration->getConnection()->getDriver()->getName(), 'Database Name' => $configuration->getConnection()->getDatabase(), 'Version Table Name' => $configuration->getMigrationsTableName(), 'Migrations Namespace' => $configuration->getMigrationsNamespace(), 'Migrations Directory' => $configuration->getMigrationsDirectory(), 'Previous Version' => $formattedVersions['prev'], 'Current Version' => $formattedVersions['current'], 'Next Version' => $formattedVersions['next'], 'Latest Version' => $formattedVersions['latest'], 'Executed Migrations' => count($executedMigrations), 'Executed Unavailable Migrations' => $numExecutedUnavailableMigrations > 0 ? '<error>' . $numExecutedUnavailableMigrations . '</error>' : 0, 'Available Migrations' => count($availableMigrations), 'New Migrations' => $newMigrations > 0 ? '<question>' . $newMigrations . '</question>' : 0];
     foreach ($info as $name => $value) {
         $this->line('    <comment>>></comment> ' . $name . ': ' . str_repeat(' ', 50 - strlen($name)) . $value);
     }
     if ($this->option('show-versions')) {
         if ($migrations = $configuration->getMigrations()) {
             $executedUnavailableMigrations = $migrations;
             $this->line("\n <info>==</info> Available Migration Versions\n");
             $this->showVersions($migrations, $configuration);
         }
         if (!empty($executedUnavailableMigrations)) {
             $this->line("\n <info>==</info> Previously Executed Unavailable Migration Versions\n");
             $this->showVersions($executedUnavailableMigrations, $configuration);
         }
     }
 }
 /**
  * Execute the console command.
  *
  * @param ConfigurationProvider $provider
  * @param Migrator              $migrator
  *
  * @throws \Doctrine\DBAL\Migrations\MigrationException
  * @return int
  */
 public function fire(ConfigurationProvider $provider, Migrator $migrator)
 {
     if (!$this->confirmToProceed()) {
         return;
     }
     $configuration = $provider->getForConnection($this->option('connection') ?: null);
     try {
         $migration = new Migration($configuration, $this->argument('version'));
     } catch (ExecutedUnavailableMigrationsException $e) {
         $this->handleExecutedUnavailableMigrationsException($e, $configuration);
     } catch (MigrationVersionException $e) {
         $this->error($e->getMessage());
     }
     if ($path = $this->option('write-sql')) {
         $migrator->migrateToFile($migration, $path);
     } else {
         $migrator->migrate($migration, $this->option('dry-run') ? true : false, $this->option('query-time') ? true : false);
     }
     foreach ($migrator->getNotes() as $note) {
         $this->line($note);
     }
 }
Пример #8
0
 /**
  * Execute the console command.
  *
  * @param ConfigurationProvider $provider
  */
 public function fire(ConfigurationProvider $provider)
 {
     $configuration = $provider->getForConnection($this->option('connection'));
     $this->line('<info>Latest version:</info> ' . $configuration->getLatestVersion());
 }
 public function test_can_get_configuration_for_specific_connection()
 {
     $this->registry->shouldReceive('getConnection')->with('connection')->andReturn($this->connection);
     $this->factory->shouldReceive('make')->with($this->connection)->andReturn('configuration');
     $this->assertEquals('configuration', $this->provider->getForConnection('connection'));
 }
Пример #10
0
 /**
  * Execute the console command.
  *
  * @param ConfigurationProvider  $provider
  * @param MigrationFileGenerator $generator
  */
 public function fire(ConfigurationProvider $provider, MigrationFileGenerator $generator)
 {
     $configuration = $provider->getForConnection();
     $filename = $generator->generate($configuration, $this->option('create'), $this->option('table'));
     $this->line(sprintf('<info>Created Migration:</info> %s', $filename));
 }