1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ControleOnline\Command; |
4
|
|
|
|
5
|
|
|
use ControleOnline\Service\DatabaseSwitchService; |
6
|
|
|
use Symfony\Component\Console\Attribute\AsCommand; |
|
|
|
|
7
|
|
|
use Symfony\Component\Console\Command\Command; |
|
|
|
|
8
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
|
|
|
|
9
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
|
|
|
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
|
|
|
11
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
|
|
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
|
|
|
13
|
|
|
|
14
|
|
|
#[AsCommand( |
15
|
|
|
name: 'tenant:migrations:migrate', |
16
|
|
|
description: 'Proxy para migrar um novo banco de dados de tenant.', |
17
|
|
|
)] |
18
|
|
|
final class MigrateCommand extends Command |
19
|
|
|
{ |
20
|
|
|
private DatabaseSwitchService $databaseSwitchService; |
21
|
|
|
|
22
|
|
|
public function __construct(DatabaseSwitchService $databaseSwitchService) |
23
|
|
|
{ |
24
|
|
|
$this->databaseSwitchService = $databaseSwitchService; |
25
|
|
|
parent::__construct(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
protected function configure(): void |
29
|
|
|
{ |
30
|
|
|
$this |
31
|
|
|
->setName('tenant:migrations:migrate') |
32
|
|
|
->setAliases(['t:m:m']) |
33
|
|
|
->setDescription('Proxy para executar doctrine:migrations:migrate para um banco de dados específico.') |
34
|
|
|
->addArgument('domain', InputArgument::OPTIONAL, 'Identificador do domínio do banco de dados') |
35
|
|
|
->addArgument('version', InputArgument::OPTIONAL, 'O número da versão (AAAAMMDDHHMMSS) ou alias (first, prev, next, latest) para migrar.', 'latest') |
36
|
|
|
->addOption('dry-run', null, InputOption::VALUE_NONE, 'Executar a migração como uma simulação.') |
37
|
|
|
->addOption('query-time', null, InputOption::VALUE_NONE, 'Medir o tempo de todas as consultas individualmente.') |
38
|
|
|
->addOption('allow-no-migration', null, InputOption::VALUE_NONE, 'Não lançar uma exceção quando nenhuma alteração for detectada.'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
42
|
|
|
{ |
43
|
|
|
$domain = $input->getArgument('domain'); |
44
|
|
|
|
45
|
|
|
if ($domain) { |
46
|
|
|
return $this->migrateByDomain($domain, $input, $output); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$domains = $this->databaseSwitchService->getAllDomains(); |
50
|
|
|
$exitCode = Command::SUCCESS; |
51
|
|
|
|
52
|
|
|
foreach ($domains as $domain) { |
53
|
|
|
$result = $this->migrateByDomain($domain, $input, $output); |
54
|
|
|
if ($result !== Command::SUCCESS) { |
55
|
|
|
$exitCode = Command::FAILURE; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $exitCode; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
protected function migrateByDomain(string $domain, InputInterface $input, OutputInterface $output): int |
63
|
|
|
{ |
64
|
|
|
$this->databaseSwitchService->switchDatabaseByDomain($domain); |
65
|
|
|
|
66
|
|
|
$newInput = new ArrayInput([ |
67
|
|
|
'version' => $input->getArgument('version'), |
68
|
|
|
'--dry-run' => $input->getOption('dry-run'), |
69
|
|
|
'--query-time' => $input->getOption('query-time'), |
70
|
|
|
'--allow-no-migration' => $input->getOption('allow-no-migration'), |
71
|
|
|
]); |
72
|
|
|
$newInput->setInteractive(false); |
73
|
|
|
|
74
|
|
|
$output->writeln(sprintf('Executando migrações para o domínio: %s', $domain)); |
75
|
|
|
|
76
|
|
|
$command = $this->getApplication()->find('doctrine:migrations:migrate'); |
77
|
|
|
return $command->run($newInput, $output); |
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