Skip to content

Commit

Permalink
Add new commands from Migrations 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jwage committed Jun 5, 2018
1 parent ae343fe commit a7f650d
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 17 deletions.
11 changes: 10 additions & 1 deletion Command/MigrationsDiffDoctrineCommand.php
Expand Up @@ -13,7 +13,6 @@
/**
* Command for generate migration classes by comparing your current database schema
* to your mapping information.
*
*/
class MigrationsDiffDoctrineCommand extends DiffCommand
{
Expand Down Expand Up @@ -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);
}
}
53 changes: 53 additions & 0 deletions Command/MigrationsDumpSchemaDoctrineCommand.php
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

namespace Doctrine\Bundle\MigrationsBundle\Command;

use Doctrine\Migrations\Tools\Console\Command\DumpSchemaCommand;
use InvalidArgumentException;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Command for dumping your current database schema to a migration.
*/
class MigrationsDumpSchemaDoctrineCommand extends DumpSchemaCommand
{
protected function configure() : void
{
parent::configure();

$this
->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);
}
}
1 change: 0 additions & 1 deletion Command/MigrationsExecuteDoctrineCommand.php
Expand Up @@ -13,7 +13,6 @@

/**
* Command for executing single migrations up or down manually.
*
*/
class MigrationsExecuteDoctrineCommand extends ExecuteCommand
{
Expand Down
1 change: 0 additions & 1 deletion Command/MigrationsGenerateDoctrineCommand.php
Expand Up @@ -13,7 +13,6 @@

/**
* Command for generating new blank migration classes
*
*/
class MigrationsGenerateDoctrineCommand extends GenerateCommand
{
Expand Down
1 change: 0 additions & 1 deletion Command/MigrationsLatestDoctrineCommand.php
Expand Up @@ -13,7 +13,6 @@

/**
* Command for outputting the latest version number.
*
*/
class MigrationsLatestDoctrineCommand extends LatestCommand
{
Expand Down
1 change: 0 additions & 1 deletion Command/MigrationsMigrateDoctrineCommand.php
Expand Up @@ -13,7 +13,6 @@

/**
* Command for executing a migration to a specified version or the latest available version.
*
*/
class MigrationsMigrateDoctrineCommand extends MigrateCommand
{
Expand Down
53 changes: 53 additions & 0 deletions Command/MigrationsRollupDoctrineCommand.php
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

namespace Doctrine\Bundle\MigrationsBundle\Command;

use Doctrine\Migrations\Tools\Console\Command\RollupCommand;
use InvalidArgumentException;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Command for rolling up your historical migration versions and inserting the dumped schema version.
*/
class MigrationsRollupDoctrineCommand extends RollupCommand
{
protected function configure() : void
{
parent::configure();

$this
->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);
}
}
1 change: 0 additions & 1 deletion Command/MigrationsStatusDoctrineCommand.php
Expand Up @@ -13,7 +13,6 @@

/**
* Command to view the status of a set of migrations.
*
*/
class MigrationsStatusDoctrineCommand extends StatusCommand
{
Expand Down
53 changes: 53 additions & 0 deletions Command/MigrationsUpToDateDoctrineCommand.php
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

namespace Doctrine\Bundle\MigrationsBundle\Command;

use Doctrine\Migrations\Tools\Console\Command\UpToDateCommand;
use InvalidArgumentException;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Command for checking if your database is up to date or not.
*/
class MigrationsUpToDateDoctrineCommand extends UpToDateCommand
{
protected function configure() : void
{
parent::configure();

$this
->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);
}
}
1 change: 0 additions & 1 deletion Command/MigrationsVersionDoctrineCommand.php
Expand Up @@ -13,7 +13,6 @@

/**
* Command for manually adding and deleting migration versions from the version table.
*
*/
class MigrationsVersionDoctrineCommand extends VersionCommand
{
Expand Down
9 changes: 9 additions & 0 deletions Resources/config/services.xml
Expand Up @@ -8,6 +8,9 @@
<service id="doctrine_migrations.diff_command" class="Doctrine\Bundle\MigrationsBundle\Command\MigrationsDiffDoctrineCommand">
<tag name="console.command" />
</service>
<service id="doctrine_migrations.dump_schema_command" class="Doctrine\Bundle\MigrationsBundle\Command\MigrationsDumpSchemaDoctrineCommand">
<tag name="console.command" />
</service>
<service id="doctrine_migrations.execute_command" class="Doctrine\Bundle\MigrationsBundle\Command\MigrationsExecuteDoctrineCommand">
<tag name="console.command" />
</service>
Expand All @@ -20,9 +23,15 @@
<service id="doctrine_migrations.migrate_command" class="Doctrine\Bundle\MigrationsBundle\Command\MigrationsMigrateDoctrineCommand">
<tag name="console.command" />
</service>
<service id="doctrine_migrations.rollup_command" class="Doctrine\Bundle\MigrationsBundle\Command\MigrationsRollupDoctrineCommand">
<tag name="console.command" />
</service>
<service id="doctrine_migrations.status_command" class="Doctrine\Bundle\MigrationsBundle\Command\MigrationsStatusDoctrineCommand">
<tag name="console.command" />
</service>
<service id="doctrine_migrations.up_to_date_command" class="Doctrine\Bundle\MigrationsBundle\Command\MigrationsUpToDateDoctrineCommand">
<tag name="console.command" />
</service>
<service id="doctrine_migrations.version_command" class="Doctrine\Bundle\MigrationsBundle\Command\MigrationsVersionDoctrineCommand">
<tag name="console.command" />
</service>
Expand Down
24 changes: 14 additions & 10 deletions Resources/doc/index.rst
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a7f650d

Please sign in to comment.