-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathDownCommand.php
More file actions
101 lines (88 loc) · 3.11 KB
/
DownCommand.php
File metadata and controls
101 lines (88 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* User: aguidet
* Date: 27/02/15
* Time: 17:14
*/
namespace Migrate\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
class DownCommand extends AbstractEnvCommand
{
protected function configure()
{
$this
->setName('migrate:down')
->setDescription('Rollback all waiting migration down to [to] option if precised')
->addArgument(
'env',
InputArgument::REQUIRED,
'Environment'
)
->addOption(
'to',
null,
InputOption::VALUE_REQUIRED,
'Migration will be downed to this migration id included'
)
->addOption(
'only',
null,
InputOption::VALUE_REQUIRED,
'If you need to down this migration id only'
)
->addOption(
'changelog-only',
null,
InputOption::VALUE_NONE,
'Mark as applied without executing SQL '
)
->addOption(
'database',
null,
InputOption::VALUE_REQUIRED,
'Database '
)
->addOption(
'driver',
null,
InputOption::VALUE_REQUIRED,
'DB driver'
);
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->checkEnv();
$this->init($input, $output);
$changeLogOnly = (bool) $input->getOption('changelog-only');
/* @var $questions QuestionHelper */
$questions = $this->getHelperSet()->get('question');
$areYouSureQuestion = new Question("Are you sure? <info>(yes/no)</info> <comment>[no]</comment>: ", 'no');
$areYouSure = $questions->ask($input, $output, $areYouSureQuestion);
if ($areYouSure == 'yes') {
$toExecute = $this->filterMigrationsToExecute($input, $output);
if (count($toExecute) == 0) {
$output->writeln("your database is already up to date");
} else {
$progress = new ProgressBar($output, count($toExecute));
$progress->setFormat(self::$progressBarFormat);
$progress->setMessage('');
$progress->start();
/* @var $migration \Migrate\Migration */
foreach ($toExecute as $migration) {
$progress->setMessage($migration->getDescription());
$this->executeDownMigration($migration, $changeLogOnly);
$progress->advance();
}
$progress->finish();
$output->writeln("");
}
} else {
$output->writeln("<error>Rollback aborted</error>");
}
}
}