Completed
Push — master ( 5fab54...da6320 )
by Derek Stephen
09:42
created

Migration   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 84%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 0
cbo 4
dl 0
loc 67
ccs 21
cts 25
cp 0.84
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 49 1
A execute() 0 11 2
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