1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apps\Console; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use Ffcms\Console\Command; |
7
|
|
|
use Ffcms\Core\Helper\Type\Any; |
8
|
|
|
use Ffcms\Core\Managers\MigrationsManager; |
9
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class MigrationApplyCommand. Apply all migrations in db |
15
|
|
|
* @package Apps\Console |
16
|
|
|
*/ |
17
|
|
|
class MigrationUpCommand extends Command |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Set command |
21
|
|
|
*/ |
22
|
|
|
public function configure() |
23
|
|
|
{ |
24
|
|
|
$this->setName('migration:up') |
25
|
|
|
->setDescription('Apply all migrations to database') |
26
|
|
|
->addArgument('name', InputArgument::OPTIONAL, 'Set search name or date (Y-m-d-H-i-s) for migration file'); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Apply all migrations into database without always apply'd |
31
|
|
|
* @param InputInterface $input |
32
|
|
|
* @param OutputInterface $output |
33
|
|
|
* @return void |
34
|
|
|
*/ |
35
|
|
|
public function execute(InputInterface $input, OutputInterface $output) |
36
|
|
|
{ |
37
|
|
|
$name = $input->getArgument('name'); |
38
|
|
|
// run migration manager - find migrations |
39
|
|
|
$manager = new MigrationsManager(null, $this->dbConnection); |
40
|
|
|
$search = $manager->search($name, false); |
|
|
|
|
41
|
|
|
if (!Any::isArray($search) || count($search) < 1) { |
|
|
|
|
42
|
|
|
$output->writeln('No migrations found'); |
43
|
|
|
return; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
// require confirmation from user each ever migration file |
47
|
|
|
$fired = false; |
48
|
|
|
foreach ($search as $migration) { |
|
|
|
|
49
|
|
|
if (!$this->confirm('Are you sure to apply migration: ' . $migration, true)) { |
50
|
|
|
continue; |
51
|
|
|
} |
52
|
|
|
$manager->makeUp($migration); |
53
|
|
|
$fired = true; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
if ($fired) { |
57
|
|
|
$output->writeln('All available migrations applied. Done.'); |
58
|
|
|
} else { |
59
|
|
|
$output->writeln('No migrations executed.'); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |