|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of Biurad opensource projects. |
|
7
|
|
|
* |
|
8
|
|
|
* PHP version 7.2 and above required |
|
9
|
|
|
* |
|
10
|
|
|
* @author Divine Niiquaye Ibok <[email protected]> |
|
11
|
|
|
* @copyright 2019 Biurad Group (https://biurad.com/) |
|
12
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause License |
|
13
|
|
|
* |
|
14
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
15
|
|
|
* file that was distributed with this source code. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace Biurad\Cycle\Commands\Migrations; |
|
19
|
|
|
|
|
20
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
|
21
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
22
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
23
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
24
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
25
|
|
|
|
|
26
|
|
|
final class ReplayCommand extends AbstractCommand |
|
27
|
|
|
{ |
|
28
|
|
|
protected static $defaultName = 'migrations:replay'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* {@inheritdoc} |
|
32
|
|
|
*/ |
|
33
|
|
|
protected function defineDescription(): string |
|
34
|
|
|
{ |
|
35
|
|
|
return 'Replay (down, up) one or multiple migrations'; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritdoc} |
|
40
|
|
|
*/ |
|
41
|
|
|
protected function defineOption(): array |
|
42
|
|
|
{ |
|
43
|
|
|
return [new InputOption('all', 'a', InputOption::VALUE_NONE, 'Replay all migrations.')]; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* {@inheritdoc} |
|
48
|
|
|
*/ |
|
49
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
50
|
|
|
{ |
|
51
|
|
|
$io = new SymfonyStyle($input, $output); |
|
52
|
|
|
|
|
53
|
|
|
if (!$this->verifyEnvironment($input, $io)) { |
|
54
|
|
|
//Making sure we can safely migrate in this environment |
|
55
|
|
|
return 1; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
$rollback = ['--force' => true]; |
|
59
|
|
|
$migrate = ['--force' => true]; |
|
60
|
|
|
|
|
61
|
|
|
if ($input->getOption('all')) { |
|
62
|
|
|
$rollback['--all'] = true; |
|
63
|
|
|
} else { |
|
64
|
|
|
$migrate['--one'] = true; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$output->writeln('Rolling back executed migration(s)...'); |
|
68
|
|
|
$this->getApplication()->find('migrations:rollback') |
|
69
|
|
|
->run(new ArrayInput($rollback), $output); |
|
70
|
|
|
|
|
71
|
|
|
$output->writeln(''); |
|
72
|
|
|
|
|
73
|
|
|
if ($io->confirm('Do you want to execute <info>migrations:start</info> immediately?', false)) { |
|
74
|
|
|
$output->writeln('Executing outstanding migration(s)...'); |
|
75
|
|
|
$this->getApplication()->find('migrations:start') |
|
76
|
|
|
->run(new ArrayInput($migrate), $output); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
return 0; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|