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..6158b60 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 @@ -78,13 +78,17 @@ All of the migrations functionality is contained in a few console commands: .. code-block:: bash - doctrine:migrations - :diff Generate a migration by comparing your current database to your mapping information. - :execute Execute a single migration version up or down manually. - :generate Generate a blank migration class. - :migrate Execute a migration to a specified version or the latest available version. - :status View the status of a set of migrations. - :version Manually add and delete migration versions from the version table. + doctrine + doctrine:migrations:diff [diff] Generate a migration by comparing your current database to your mapping information. + doctrine:migrations:dump-schema [dump-schema] Dump the schema for your database to a migration. + doctrine:migrations:execute [execute] Execute a single migration version up or down manually. + doctrine:migrations:generate [generate] Generate a blank migration class. + doctrine:migrations:latest [latest] Outputs the latest version number + doctrine:migrations:migrate [migrate] Execute a migration to a specified version or the latest available version. + doctrine:migrations:rollup [rollup] Rollup migrations by deleting all tracked versions and insert the one version that exists. + doctrine:migrations:status [status] View the status of a set of migrations. + doctrine:migrations:up-to-date [up-to-date] Tells you if your schema is up-to-date. + doctrine:migrations:version [version] Manually add and delete migration versions from the version table. Start by getting the status of migrations in your application by running the ``status`` command: @@ -102,7 +106,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 +135,7 @@ like the following:: declare(strict_types=1); - namespace DoctrineMigrations; + namespace App\Migrations; use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; diff --git a/composer.lock b/composer.lock index 5e7f464..b8b0f3f 100644 --- a/composer.lock +++ b/composer.lock @@ -789,12 +789,12 @@ "source": { "type": "git", "url": "https://github.com/doctrine/migrations.git", - "reference": "763fa4a36700b2f7bc23401c49f9ba04ca0adbeb" + "reference": "38e5cd6c78a2a9e7c0ae7ecae44795a6877d33bd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/migrations/zipball/763fa4a36700b2f7bc23401c49f9ba04ca0adbeb", - "reference": "763fa4a36700b2f7bc23401c49f9ba04ca0adbeb", + "url": "https://api.github.com/repos/doctrine/migrations/zipball/38e5cd6c78a2a9e7c0ae7ecae44795a6877d33bd", + "reference": "38e5cd6c78a2a9e7c0ae7ecae44795a6877d33bd", "shasum": "" }, "require": { @@ -859,7 +859,7 @@ "database", "migrations" ], - "time": "2018-06-04T20:00:45+00:00" + "time": "2018-06-05T16:46:15+00:00" }, { "name": "jdorn/sql-formatter", @@ -3918,16 +3918,16 @@ }, { "name": "phpunit/phpunit", - "version": "7.2.3", + "version": "7.2.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "42bb8f5b2cb36483907a20f45e4cd1665c24d8a7" + "reference": "00bc0b93f0ff4f557e9ea766557fde96da9a03dd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/42bb8f5b2cb36483907a20f45e4cd1665c24d8a7", - "reference": "42bb8f5b2cb36483907a20f45e4cd1665c24d8a7", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/00bc0b93f0ff4f557e9ea766557fde96da9a03dd", + "reference": "00bc0b93f0ff4f557e9ea766557fde96da9a03dd", "shasum": "" }, "require": { @@ -3998,7 +3998,7 @@ "testing", "xunit" ], - "time": "2018-06-03T06:05:05+00:00" + "time": "2018-06-05T03:40:05+00:00" }, { "name": "sebastian/code-unit-reverse-lookup",