Skip to content

Commit 3ec4c3c

Browse files
committed
Add new commands from Migrations 2.0
1 parent ae343fe commit 3ec4c3c

14 files changed

+204
-28
lines changed

Command/MigrationsDiffDoctrineCommand.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Doctrine\Bundle\MigrationsBundle\Command;
66

77
use Doctrine\Migrations\Tools\Console\Command\DiffCommand;
8+
use InvalidArgumentException;
89
use Symfony\Bundle\FrameworkBundle\Console\Application;
910
use Symfony\Component\Console\Input\InputInterface;
1011
use Symfony\Component\Console\Input\InputOption;
@@ -13,7 +14,6 @@
1314
/**
1415
* Command for generate migration classes by comparing your current database schema
1516
* to your mapping information.
16-
*
1717
*/
1818
class MigrationsDiffDoctrineCommand extends DiffCommand
1919
{
@@ -41,4 +41,14 @@ public function initialize(InputInterface $input, OutputInterface $output) : voi
4141

4242
parent::initialize($input, $output);
4343
}
44+
45+
public function execute(InputInterface $input, OutputInterface $output) : ?int
46+
{
47+
// EM and DB options cannot be set at same time
48+
if ($input->getOption('em') !== null && $input->getOption('db') !== null) {
49+
throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
50+
}
51+
52+
return parent::execute($input, $output);
53+
}
4454
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Bundle\MigrationsBundle\Command;
6+
7+
use Doctrine\Migrations\Tools\Console\Command\DumpSchemaCommand;
8+
use InvalidArgumentException;
9+
use Symfony\Bundle\FrameworkBundle\Console\Application;
10+
use Symfony\Component\Console\Input\InputInterface;
11+
use Symfony\Component\Console\Input\InputOption;
12+
use Symfony\Component\Console\Output\OutputInterface;
13+
14+
/**
15+
* Command for dumping your current database schema to a migration.
16+
*/
17+
class MigrationsDumpSchemaDoctrineCommand extends DumpSchemaCommand
18+
{
19+
protected function configure() : void
20+
{
21+
parent::configure();
22+
23+
$this
24+
->setName('doctrine:migrations:dump-schema')
25+
->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.')
26+
->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.')
27+
->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command.')
28+
;
29+
}
30+
31+
public function initialize(InputInterface $input, OutputInterface $output) : void
32+
{
33+
/** @var Application $application */
34+
$application = $this->getApplication();
35+
36+
Helper\DoctrineCommandHelper::setApplicationHelper($application, $input);
37+
38+
$configuration = $this->getMigrationConfiguration($input, $output);
39+
DoctrineCommand::configureMigrations($application->getKernel()->getContainer(), $configuration);
40+
41+
parent::initialize($input, $output);
42+
}
43+
44+
public function execute(InputInterface $input, OutputInterface $output) : ?int
45+
{
46+
// EM and DB options cannot be set at same time
47+
if ($input->getOption('em') !== null && $input->getOption('db') !== null) {
48+
throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
49+
}
50+
51+
return parent::execute($input, $output);
52+
}
53+
}

Command/MigrationsExecuteDoctrineCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
/**
1515
* Command for executing single migrations up or down manually.
16-
*
1716
*/
1817
class MigrationsExecuteDoctrineCommand extends ExecuteCommand
1918
{

Command/MigrationsGenerateDoctrineCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
/**
1515
* Command for generating new blank migration classes
16-
*
1716
*/
1817
class MigrationsGenerateDoctrineCommand extends GenerateCommand
1918
{

Command/MigrationsLatestDoctrineCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
/**
1515
* Command for outputting the latest version number.
16-
*
1716
*/
1817
class MigrationsLatestDoctrineCommand extends LatestCommand
1918
{

Command/MigrationsMigrateDoctrineCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
/**
1515
* Command for executing a migration to a specified version or the latest available version.
16-
*
1716
*/
1817
class MigrationsMigrateDoctrineCommand extends MigrateCommand
1918
{
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Bundle\MigrationsBundle\Command;
6+
7+
use Doctrine\Migrations\Tools\Console\Command\RollupCommand;
8+
use InvalidArgumentException;
9+
use Symfony\Bundle\FrameworkBundle\Console\Application;
10+
use Symfony\Component\Console\Input\InputInterface;
11+
use Symfony\Component\Console\Input\InputOption;
12+
use Symfony\Component\Console\Output\OutputInterface;
13+
14+
/**
15+
* Command for rolling up your historical migration versions and inserting the dumped schema version.
16+
*/
17+
class MigrationsRollupDoctrineCommand extends RollupCommand
18+
{
19+
protected function configure() : void
20+
{
21+
parent::configure();
22+
23+
$this
24+
->setName('doctrine:migrations:rollup')
25+
->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.')
26+
->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.')
27+
->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command.')
28+
;
29+
}
30+
31+
public function initialize(InputInterface $input, OutputInterface $output) : void
32+
{
33+
/** @var Application $application */
34+
$application = $this->getApplication();
35+
36+
Helper\DoctrineCommandHelper::setApplicationHelper($application, $input);
37+
38+
$configuration = $this->getMigrationConfiguration($input, $output);
39+
DoctrineCommand::configureMigrations($application->getKernel()->getContainer(), $configuration);
40+
41+
parent::initialize($input, $output);
42+
}
43+
44+
public function execute(InputInterface $input, OutputInterface $output) : ?int
45+
{
46+
// EM and DB options cannot be set at same time
47+
if ($input->getOption('em') !== null && $input->getOption('db') !== null) {
48+
throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
49+
}
50+
51+
return parent::execute($input, $output);
52+
}
53+
}

Command/MigrationsStatusDoctrineCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
/**
1515
* Command to view the status of a set of migrations.
16-
*
1716
*/
1817
class MigrationsStatusDoctrineCommand extends StatusCommand
1918
{
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Bundle\MigrationsBundle\Command;
6+
7+
use Doctrine\Migrations\Tools\Console\Command\UpToDateCommand;
8+
use InvalidArgumentException;
9+
use Symfony\Bundle\FrameworkBundle\Console\Application;
10+
use Symfony\Component\Console\Input\InputInterface;
11+
use Symfony\Component\Console\Input\InputOption;
12+
use Symfony\Component\Console\Output\OutputInterface;
13+
14+
/**
15+
* Command for checking if your database is up to date or not.
16+
*/
17+
class MigrationsUpToDateDoctrineCommand extends UpToDateCommand
18+
{
19+
protected function configure() : void
20+
{
21+
parent::configure();
22+
23+
$this
24+
->setName('doctrine:migrations:up-to-date')
25+
->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.')
26+
->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.')
27+
->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command.')
28+
;
29+
}
30+
31+
public function initialize(InputInterface $input, OutputInterface $output) : void
32+
{
33+
/** @var Application $application */
34+
$application = $this->getApplication();
35+
36+
Helper\DoctrineCommandHelper::setApplicationHelper($application, $input);
37+
38+
$configuration = $this->getMigrationConfiguration($input, $output);
39+
DoctrineCommand::configureMigrations($application->getKernel()->getContainer(), $configuration);
40+
41+
parent::initialize($input, $output);
42+
}
43+
44+
public function execute(InputInterface $input, OutputInterface $output) : ?int
45+
{
46+
// EM and DB options cannot be set at same time
47+
if ($input->getOption('em') !== null && $input->getOption('db') !== null) {
48+
throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
49+
}
50+
51+
return parent::execute($input, $output);
52+
}
53+
}

Command/MigrationsVersionDoctrineCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
/**
1515
* Command for manually adding and deleting migration versions from the version table.
16-
*
1716
*/
1817
class MigrationsVersionDoctrineCommand extends VersionCommand
1918
{

0 commit comments

Comments
 (0)