/** * Do the configured migrations in the given migration file for the given workspace * * By default the up direction is applied, using the direction parameter this can * be changed. * * @param string $workspace The name of the workspace you want to migrate. This workspace must exist. * @param string $version The version of the migration configuration you want to use. * @param boolean $confirmation Confirm application of this migration, only needed if the given migration contains any warnings. * @param string $direction The direction to work in, MigrationStatus::DIRECTION_UP or MigrationStatus::DIRECTION_DOWN * @return void */ public function migrateCommand($workspace, $version, $confirmation = FALSE, $direction = MigrationStatus::DIRECTION_UP) { $context = $this->prepareContext($workspace); $migrationConfiguration = $direction === MigrationStatus::DIRECTION_UP ? $this->migrationFactory->getMigrationForVersion($version)->getUpConfiguration() : $this->migrationFactory->getMigrationForVersion($version)->getDownConfiguration(); $this->outputCommentsAndWarnings($migrationConfiguration); if ($migrationConfiguration->hasWarnings() && $confirmation === FALSE) { $this->outputLine(); $this->outputLine('Migration has warnings. You need to confirm execution by adding the "--confirmation TRUE" option to the command.'); $this->quit(1); } $nodeMigrationService = new NodeMigration($context, $migrationConfiguration->getMigration()); switch ($direction) { case MigrationStatus::DIRECTION_UP: $nodeMigrationService->migrateUp(); break; case MigrationStatus::DIRECTION_DOWN: $nodeMigrationService->migrateDown(); break; default: } $migrationStatus = new MigrationStatus($version, $workspace, $direction, new \DateTime()); $this->migrationStatusRepository->add($migrationStatus); $this->outputLine(); $this->outputLine('Successfully applied migration.'); }
/** * Do the configured migrations in the given migration. * * By default the up direction is applied, using the direction parameter this can * be changed. * * @param string $version The version of the migration configuration you want to use. * @param boolean $confirmation Confirm application of this migration, only needed if the given migration contains any warnings. * @param string $direction The direction to work in, MigrationStatus::DIRECTION_UP or MigrationStatus::DIRECTION_DOWN * @return void */ public function migrateCommand($version, $confirmation = false, $direction = MigrationStatus::DIRECTION_UP) { try { $migrationConfiguration = $direction === MigrationStatus::DIRECTION_UP ? $this->migrationFactory->getMigrationForVersion($version)->getUpConfiguration() : $this->migrationFactory->getMigrationForVersion($version)->getDownConfiguration(); $this->outputCommentsAndWarnings($migrationConfiguration); if ($migrationConfiguration->hasWarnings() && $confirmation === false) { $this->outputLine(); $this->outputLine('Migration has warnings. You need to confirm execution by adding the "--confirmation TRUE" option to the command.'); $this->quit(1); } $nodeMigrationService = new NodeMigration($migrationConfiguration->getMigration()); $nodeMigrationService->execute(); $migrationStatus = new MigrationStatus($version, $direction, new \DateTime()); $this->migrationStatusRepository->add($migrationStatus); $this->outputLine(); $this->outputLine('Successfully applied migration.'); } catch (MigrationException $e) { $this->outputLine(); $this->outputLine('Error: ' . $e->getMessage()); $this->quit(1); } catch (DatabaseException $exception) { $this->outputLine(); $this->outputLine('An exception occurred during the migration, run a ./flow doctrine:migrate and run the migration again.'); $this->quit(1); } }