Completed
Push — master ( 20cc15...500683 )
by Derek Stephen
06:57 queued 12s
created

Migration   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 60.87%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 70
ccs 14
cts 23
cp 0.6087
rs 10
c 0
b 0
f 0

2 Methods

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