1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* This file is part of the daikon-cqrs/boot project. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Daikon\Boot\Console\Command\Migrate; |
10
|
|
|
|
11
|
|
|
use Daikon\Dbal\Migration\MigrationInterface; |
12
|
|
|
use Daikon\Dbal\Migration\MigrationTargetMap; |
13
|
|
|
use Daikon\Interop\InvalidArgumentException; |
14
|
|
|
use Symfony\Component\Console\Command\Command; |
|
|
|
|
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
16
|
|
|
use Symfony\Component\Console\Input\InputOption; |
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
18
|
|
|
|
19
|
|
|
final class MigrateDown extends Command |
20
|
|
|
{ |
21
|
|
|
private MigrationTargetMap $migrationTargetMap; |
22
|
|
|
|
23
|
|
|
public function __construct(MigrationTargetMap $migrationTargetMap) |
24
|
|
|
{ |
25
|
|
|
$this->migrationTargetMap = $migrationTargetMap; |
26
|
|
|
|
27
|
|
|
parent::__construct(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
protected function configure(): void |
31
|
|
|
{ |
32
|
|
|
$this |
33
|
|
|
->setName('migrate:down') |
34
|
|
|
->setDescription('Migrate down to a specified migration version.') |
35
|
|
|
->addOption( |
36
|
|
|
'target', |
37
|
|
|
null, |
38
|
|
|
InputOption::VALUE_REQUIRED, |
39
|
|
|
'Name of the target to migrate (if omitted all enabled targets will be migrated).' |
40
|
|
|
) |
41
|
|
|
->addOption( |
42
|
|
|
'to', |
43
|
|
|
null, |
44
|
|
|
InputOption::VALUE_REQUIRED, |
45
|
|
|
'The version to migrate towards (if omitted all previous migrations will be reversed if possible).' |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
50
|
|
|
{ |
51
|
|
|
$target = $input->getOption('target'); |
52
|
|
|
$version = intval($input->getOption('to')); |
53
|
|
|
|
54
|
|
|
foreach ($this->migrationTargetMap->getEnabledTargets() as $targetKey => $migrationTarget) { |
55
|
|
|
if ($target && $target !== $targetKey) { |
56
|
|
|
continue; |
57
|
|
|
} |
58
|
|
|
$output->writeln(sprintf('Reversing migrations for target <options=bold>%s</>', $targetKey)); |
59
|
|
|
try { |
60
|
|
|
$reversedMigrations = $migrationTarget->migrate(MigrationInterface::MIGRATE_DOWN, $version); |
61
|
|
|
if ($reversedMigrations->count() > 0) { |
62
|
|
|
foreach ($reversedMigrations as $migration) { |
63
|
|
|
$output->writeln(sprintf( |
64
|
|
|
' <info>Reversed migration version %d (%s)</info>', |
65
|
|
|
$migration->getVersion(), |
66
|
|
|
$migration->getName() |
67
|
|
|
)); |
68
|
|
|
} |
69
|
|
|
} else { |
70
|
|
|
$output->writeln(' <comment>No reversible migrations found</comment>'); |
71
|
|
|
} |
72
|
|
|
} catch (InvalidArgumentException $exception) { |
73
|
|
|
$output->writeln(' <error>'.$exception->getMessage().'</error>'); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return 0; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths