1
|
|
|
<?php |
2
|
|
|
namespace Del\Common\Command; |
3
|
|
|
|
4
|
|
|
use Del\Common\ContainerService; |
5
|
|
|
use Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand; |
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
10
|
|
|
|
11
|
|
|
class Migration extends MigrateCommand |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
|
15
|
1 |
|
protected function configure() |
16
|
|
|
{ |
17
|
|
|
|
18
|
1 |
|
$this |
19
|
1 |
|
->setName('migrate') |
20
|
1 |
|
->setDescription('Execute migrations.') |
21
|
1 |
|
->addArgument('vendor', InputArgument::OPTIONAL, 'The vendor directory containing the migrations.') |
22
|
1 |
|
->addArgument('version', InputArgument::OPTIONAL, 'The version number (YYYYMMDDHHMMSS) or alias (first, prev, next, latest) to migrate to.', 'latest') |
23
|
1 |
|
->addOption('write-sql', null, InputOption::VALUE_NONE, 'The path to output the migration SQL file instead of executing it.') |
24
|
1 |
|
->addOption('dry-run', null, InputOption::VALUE_NONE, 'Execute the migration as a dry run.') |
25
|
1 |
|
->addOption('query-time', null, InputOption::VALUE_NONE, 'Time all the queries individually.') |
26
|
1 |
|
->addOption('allow-no-migration', null, InputOption::VALUE_NONE, 'Don\'t throw an exception if no migration is available (CI).') |
27
|
1 |
|
->setHelp(<<<EOT |
28
|
|
|
The <info>%command.name%</info> command executes migrate in a specified directory |
29
|
|
|
|
30
|
|
|
<info>%command.full_name% foldername</info> |
31
|
|
|
|
32
|
|
|
The <info>%command.name%</info> command executes a migration to a specified version or the latest available version: |
33
|
|
|
|
34
|
|
|
<info>%command.full_name%</info> |
35
|
|
|
|
36
|
|
|
You can optionally manually specify the version you wish to migrate to: |
37
|
|
|
|
38
|
|
|
<info>%command.full_name% YYYYMMDDHHMMSS</info> |
39
|
|
|
|
40
|
|
|
You can specify the version you wish to migrate to using an alias: |
41
|
|
|
|
42
|
|
|
<info>%command.full_name% prev</info> |
43
|
|
|
|
44
|
|
|
You can also execute the migration as a <comment>--dry-run</comment>: |
45
|
|
|
|
46
|
|
|
<info>%command.full_name% YYYYMMDDHHMMSS --dry-run</info> |
47
|
|
|
|
48
|
|
|
You can output the would be executed SQL statements to a file with <comment>--write-sql</comment>: |
49
|
|
|
|
50
|
|
|
<info>%command.full_name% YYYYMMDDHHMMSS --write-sql</info> |
51
|
|
|
|
52
|
|
|
Or you can also execute the migration without a warning message which you need to interact with: |
53
|
|
|
|
54
|
|
|
<info>%command.full_name% --no-interaction</info> |
55
|
|
|
|
56
|
|
|
You can also time all the different queries if you wanna know which one is taking so long: |
57
|
|
|
|
58
|
|
|
<info>%command.full_name% --query-time</info> |
59
|
|
|
EOT |
60
|
1 |
|
); |
61
|
1 |
|
$this->addOption('configuration', null, InputOption::VALUE_OPTIONAL, 'The path to a migrations configuration file.'); |
62
|
1 |
|
$this->addOption('db-configuration', null, InputOption::VALUE_OPTIONAL, 'The path to a database connection configuration file.'); |
63
|
1 |
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
1 |
|
public function execute(InputInterface $input, OutputInterface $output) |
67
|
|
|
{ |
68
|
1 |
|
if ($path = $input->getArgument('vendor')) { |
69
|
1 |
|
$path = 'vendor/'.$path.'/migrations'; |
70
|
1 |
|
$config = $this->getMigrationConfiguration($input, $output); |
71
|
1 |
|
$config->setMigrationsDirectory($path); |
72
|
1 |
|
$config->registerMigrationsFromDirectory($path); |
73
|
|
|
$this->setMigrationConfiguration($config); |
74
|
|
|
} |
75
|
|
|
parent::execute($input, $output); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|