From 1f04ba5c2fb14a50cd3517e166bc8efd165ad77f Mon Sep 17 00:00:00 2001 From: "Jonathan H. Wage" Date: Tue, 5 Jun 2018 16:16:33 +0100 Subject: [PATCH] Add new commands from Migrations 2.0 --- Command/MigrationsDiffDoctrineCommand.php | 11 +++- .../MigrationsDumpSchemaDoctrineCommand.php | 53 +++++++++++++++++++ Command/MigrationsExecuteDoctrineCommand.php | 1 - Command/MigrationsGenerateDoctrineCommand.php | 1 - Command/MigrationsLatestDoctrineCommand.php | 1 - Command/MigrationsMigrateDoctrineCommand.php | 1 - Command/MigrationsRollupDoctrineCommand.php | 53 +++++++++++++++++++ Command/MigrationsStatusDoctrineCommand.php | 1 - Command/MigrationsUpToDateDoctrineCommand.php | 53 +++++++++++++++++++ Command/MigrationsVersionDoctrineCommand.php | 1 - Resources/config/services.xml | 9 ++++ Resources/doc/index.rst | 6 +-- 12 files changed, 181 insertions(+), 10 deletions(-) create mode 100644 Command/MigrationsDumpSchemaDoctrineCommand.php create mode 100644 Command/MigrationsRollupDoctrineCommand.php create mode 100644 Command/MigrationsUpToDateDoctrineCommand.php diff --git a/Command/MigrationsDiffDoctrineCommand.php b/Command/MigrationsDiffDoctrineCommand.php index 102be61..eccf982 100644 --- a/Command/MigrationsDiffDoctrineCommand.php +++ b/Command/MigrationsDiffDoctrineCommand.php @@ -13,7 +13,6 @@ /** * Command for generate migration classes by comparing your current database schema * to your mapping information. - * */ class MigrationsDiffDoctrineCommand extends DiffCommand { @@ -41,4 +40,14 @@ public function initialize(InputInterface $input, OutputInterface $output) : voi parent::initialize($input, $output); } + + public function execute(InputInterface $input, OutputInterface $output) : ?int + { + // EM and DB options cannot be set at same time + if ($input->getOption('em') !== null && $input->getOption('db') !== null) { + throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.'); + } + + return parent::execute($input, $output); + } } diff --git a/Command/MigrationsDumpSchemaDoctrineCommand.php b/Command/MigrationsDumpSchemaDoctrineCommand.php new file mode 100644 index 0000000..1cdcad7 --- /dev/null +++ b/Command/MigrationsDumpSchemaDoctrineCommand.php @@ -0,0 +1,53 @@ +setName('doctrine:migrations:dump-schema') + ->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.') + ->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.') + ->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command.') + ; + } + + public function initialize(InputInterface $input, OutputInterface $output) : void + { + /** @var Application $application */ + $application = $this->getApplication(); + + Helper\DoctrineCommandHelper::setApplicationHelper($application, $input); + + $configuration = $this->getMigrationConfiguration($input, $output); + DoctrineCommand::configureMigrations($application->getKernel()->getContainer(), $configuration); + + parent::initialize($input, $output); + } + + public function execute(InputInterface $input, OutputInterface $output) : ?int + { + // EM and DB options cannot be set at same time + if ($input->getOption('em') !== null && $input->getOption('db') !== null) { + throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.'); + } + + return parent::execute($input, $output); + } +} diff --git a/Command/MigrationsExecuteDoctrineCommand.php b/Command/MigrationsExecuteDoctrineCommand.php index ae5f982..64a1f42 100644 --- a/Command/MigrationsExecuteDoctrineCommand.php +++ b/Command/MigrationsExecuteDoctrineCommand.php @@ -13,7 +13,6 @@ /** * Command for executing single migrations up or down manually. - * */ class MigrationsExecuteDoctrineCommand extends ExecuteCommand { diff --git a/Command/MigrationsGenerateDoctrineCommand.php b/Command/MigrationsGenerateDoctrineCommand.php index dd8e337..a2796ce 100644 --- a/Command/MigrationsGenerateDoctrineCommand.php +++ b/Command/MigrationsGenerateDoctrineCommand.php @@ -13,7 +13,6 @@ /** * Command for generating new blank migration classes - * */ class MigrationsGenerateDoctrineCommand extends GenerateCommand { diff --git a/Command/MigrationsLatestDoctrineCommand.php b/Command/MigrationsLatestDoctrineCommand.php index ac72e32..988e0ae 100644 --- a/Command/MigrationsLatestDoctrineCommand.php +++ b/Command/MigrationsLatestDoctrineCommand.php @@ -13,7 +13,6 @@ /** * Command for outputting the latest version number. - * */ class MigrationsLatestDoctrineCommand extends LatestCommand { diff --git a/Command/MigrationsMigrateDoctrineCommand.php b/Command/MigrationsMigrateDoctrineCommand.php index 074e417..e5c9a68 100644 --- a/Command/MigrationsMigrateDoctrineCommand.php +++ b/Command/MigrationsMigrateDoctrineCommand.php @@ -13,7 +13,6 @@ /** * Command for executing a migration to a specified version or the latest available version. - * */ class MigrationsMigrateDoctrineCommand extends MigrateCommand { diff --git a/Command/MigrationsRollupDoctrineCommand.php b/Command/MigrationsRollupDoctrineCommand.php new file mode 100644 index 0000000..683e72c --- /dev/null +++ b/Command/MigrationsRollupDoctrineCommand.php @@ -0,0 +1,53 @@ +setName('doctrine:migrations:rollup') + ->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.') + ->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.') + ->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command.') + ; + } + + public function initialize(InputInterface $input, OutputInterface $output) : void + { + /** @var Application $application */ + $application = $this->getApplication(); + + Helper\DoctrineCommandHelper::setApplicationHelper($application, $input); + + $configuration = $this->getMigrationConfiguration($input, $output); + DoctrineCommand::configureMigrations($application->getKernel()->getContainer(), $configuration); + + parent::initialize($input, $output); + } + + public function execute(InputInterface $input, OutputInterface $output) : ?int + { + // EM and DB options cannot be set at same time + if ($input->getOption('em') !== null && $input->getOption('db') !== null) { + throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.'); + } + + return parent::execute($input, $output); + } +} diff --git a/Command/MigrationsStatusDoctrineCommand.php b/Command/MigrationsStatusDoctrineCommand.php index a2e8930..9ec3c13 100644 --- a/Command/MigrationsStatusDoctrineCommand.php +++ b/Command/MigrationsStatusDoctrineCommand.php @@ -13,7 +13,6 @@ /** * Command to view the status of a set of migrations. - * */ class MigrationsStatusDoctrineCommand extends StatusCommand { diff --git a/Command/MigrationsUpToDateDoctrineCommand.php b/Command/MigrationsUpToDateDoctrineCommand.php new file mode 100644 index 0000000..fb72d88 --- /dev/null +++ b/Command/MigrationsUpToDateDoctrineCommand.php @@ -0,0 +1,53 @@ +setName('doctrine:migrations:up-to-date') + ->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.') + ->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.') + ->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command.') + ; + } + + public function initialize(InputInterface $input, OutputInterface $output) : void + { + /** @var Application $application */ + $application = $this->getApplication(); + + Helper\DoctrineCommandHelper::setApplicationHelper($application, $input); + + $configuration = $this->getMigrationConfiguration($input, $output); + DoctrineCommand::configureMigrations($application->getKernel()->getContainer(), $configuration); + + parent::initialize($input, $output); + } + + public function execute(InputInterface $input, OutputInterface $output) : ?int + { + // EM and DB options cannot be set at same time + if ($input->getOption('em') !== null && $input->getOption('db') !== null) { + throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.'); + } + + return parent::execute($input, $output); + } +} diff --git a/Command/MigrationsVersionDoctrineCommand.php b/Command/MigrationsVersionDoctrineCommand.php index 33b036d..db591ba 100644 --- a/Command/MigrationsVersionDoctrineCommand.php +++ b/Command/MigrationsVersionDoctrineCommand.php @@ -13,7 +13,6 @@ /** * Command for manually adding and deleting migration versions from the version table. - * */ class MigrationsVersionDoctrineCommand extends VersionCommand { diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 89639ec..02ae64d 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -8,6 +8,9 @@ + + + @@ -20,9 +23,15 @@ + + + + + + diff --git a/Resources/doc/index.rst b/Resources/doc/index.rst index c6c2bac..e8cff2d 100644 --- a/Resources/doc/index.rst +++ b/Resources/doc/index.rst @@ -55,7 +55,7 @@ You can configure the path, namespace, table_name, name, organize_migrations and # app/config/config.yml doctrine_migrations: dir_name: "%kernel.root_dir%/Migrations" - namespace: "DoctrineMigrations" + namespace: "App\\Migrations" table_name: "migration_versions" column_name: "version" column_length: 14 @@ -102,7 +102,7 @@ the ``status`` command: >> Configuration Source: manually configured >> Version Table Name: migration_versions >> Version Column Name: version - >> Migrations Namespace: DoctrineMigrations + >> Migrations Namespace: App\Migrations >> Migrations Directory: /path/to/project/app/Migrations >> Previous Version: Already at first version >> Current Version: 0 @@ -131,7 +131,7 @@ like the following:: declare(strict_types=1); - namespace DoctrineMigrations; + namespace App\Migrations; use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration;