1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Schnittstabil\Dartisan\Commands; |
4
|
|
|
|
5
|
|
|
use Garden\Cli\Cli; |
6
|
|
|
use Garden\Cli\Args; |
7
|
|
|
use Illuminate\Database\Migrations\Migrator; |
8
|
|
|
|
9
|
|
|
class MigrateCommand extends Command |
10
|
|
|
{ |
11
|
|
|
use DatabaseAwareCommandTrait; |
12
|
|
|
use MigrationAwareCommandTrait; |
13
|
|
|
|
14
|
|
|
public static $name = 'migrate'; |
15
|
|
|
protected $args; |
16
|
|
|
protected $migrator; |
17
|
|
|
protected $defaultPath; |
18
|
|
|
|
19
|
|
|
public function __construct(callable $outputFormatter, Args $args, Migrator $migrator, $defaultPath) |
20
|
|
|
{ |
21
|
|
|
parent::__construct($outputFormatter); |
22
|
|
|
$this->args = $args; |
23
|
|
|
$this->migrator = $migrator; |
24
|
|
|
$this->defaultPath = $defaultPath; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function run() |
28
|
|
|
{ |
29
|
|
|
$path = $this->args->getOpt('path', $this->defaultPath); |
30
|
|
|
$this->migrator->run($path, [ |
31
|
|
|
'pretend' => $this->args->getOpt('pretend', null), |
32
|
|
|
'step' => $this->args->getOpt('step', null), |
33
|
|
|
]); |
34
|
|
|
$this->echoNotes($this->migrator->getNotes()); |
35
|
|
|
return 0; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public static function register(Cli $cli) |
39
|
|
|
{ |
40
|
|
|
$cli = static::registerDatabaseOpts($cli); |
41
|
|
|
$cli = static::registerMigrationOpts($cli); |
42
|
|
|
|
43
|
|
|
return $cli |
44
|
|
|
->command(static::$name) |
45
|
|
|
->description('Run the database migrations.') |
46
|
|
|
->opt('path', 'The path of migrations files to be executed.') |
47
|
|
|
->opt('pretend', 'Dump the SQL queries that would be run.') |
48
|
|
|
->opt('step', 'Force the migrations to be run so they can be rolled back individually.'); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|