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 Biurad\Cycle\Compiler; |
21
|
|
|
use Biurad\Cycle\Generators\ShowChanges; |
22
|
|
|
use Biurad\Cycle\Migrator; |
23
|
|
|
use Cycle\Schema\Generator\SyncTables; |
24
|
|
|
use Cycle\Schema\Registry; |
25
|
|
|
use Spiral\Migrations\Config\MigrationConfig; |
26
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
27
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
28
|
|
|
|
29
|
|
|
final class SyncCommand extends AbstractCommand |
30
|
|
|
{ |
31
|
|
|
protected static $defaultName = 'migrations:sync'; |
32
|
|
|
|
33
|
|
|
/** @var Registry */ |
34
|
|
|
private $registry; |
35
|
|
|
|
36
|
|
|
/** @var Compiler */ |
37
|
|
|
private $compiler; |
38
|
|
|
|
39
|
|
|
public function __construct(Migrator $migrator, MigrationConfig $config, Registry $registry, Compiler $compiler) |
40
|
|
|
{ |
41
|
|
|
$this->compiler = $compiler; |
42
|
|
|
$this->registry = $registry; |
43
|
|
|
|
44
|
|
|
parent::__construct($migrator, $config); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
|
|
protected function defineDescription(): string |
51
|
|
|
{ |
52
|
|
|
return 'Sync Cycle ORM schema with database without intermediate migration (risk operation)'; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
59
|
|
|
{ |
60
|
|
|
if (!$this->verifyConfigured($output)) { |
61
|
|
|
return 1; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$this->compiler->addGenerator($show = new ShowChanges($output)); |
65
|
|
|
$this->compiler->addGenerator(new SyncTables()); |
66
|
|
|
$this->compiler->compile($this->registry); |
67
|
|
|
|
68
|
|
|
if ($show->hasChanges()) { |
69
|
|
|
$output->writeln("\n<info>ORM Schema has been synchronized</info>"); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return 0; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|