-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathUpCommand.php
More file actions
87 lines (76 loc) · 2.53 KB
/
UpCommand.php
File metadata and controls
87 lines (76 loc) · 2.53 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
<?php
/**
* User: aguidet
* Date: 27/02/15
* Time: 17:13
*/
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;
class UpCommand extends AbstractEnvCommand
{
protected function configure()
{
$this
->setName('migrate:up')
->setDescription('Execute all waiting migration up to [to] option if precised')
->addArgument(
'env',
InputArgument::REQUIRED,
'Environment'
)
->addOption(
'to',
null,
InputOption::VALUE_REQUIRED,
'Migration will be uped up to this migration id included'
)
->addOption(
'only',
null,
InputOption::VALUE_REQUIRED,
'If you need to up 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');
$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->executeUpMigration($migration, $changeLogOnly);
$progress->advance();
}
$progress->finish();
$output->writeln("");
}
}
}