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 MigrateRollbackCommand extends Command |
10
|
|
|
{ |
11
|
|
|
use DatabaseAwareCommandTrait; |
12
|
|
|
use MigrationAwareCommandTrait; |
13
|
|
|
|
14
|
|
|
public static $name = 'migrate:rollback'; |
15
|
|
|
protected $args; |
16
|
|
|
protected $migrator; |
17
|
|
|
protected $migrationsPath; |
18
|
|
|
|
19
|
|
View Code Duplication |
public function __construct(callable $outputFormatter, Args $args, Migrator $migrator, $migrationsPath) |
20
|
|
|
{ |
21
|
|
|
parent::__construct($outputFormatter); |
22
|
|
|
$this->args = $args; |
23
|
|
|
$this->migrator = $migrator; |
24
|
|
|
$this->migrationsPath = $migrationsPath; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function run() |
28
|
|
|
{ |
29
|
|
|
if (!$this->migrator->repositoryExists()) { |
30
|
|
|
$this->echoError('No migration table found.'); |
31
|
|
|
return 1; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
$path = $this->args->getOpt('path', $this->migrationsPath); |
35
|
|
|
$this->migrator->rollback($path, [ |
36
|
|
|
'pretend' => $this->args->getOpt('pretend', null), |
37
|
|
|
'step' => $this->args->getOpt('step', null), |
38
|
|
|
]); |
39
|
|
|
$this->echoNotes($this->migrator->getNotes()); |
40
|
|
|
|
41
|
|
|
return 0; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public static function register(Cli $cli) |
45
|
|
|
{ |
46
|
|
|
$cli = static::registerDatabaseOpts($cli); |
47
|
|
|
$cli = static::registerMigrationOpts($cli); |
48
|
|
|
|
49
|
|
|
return $cli |
50
|
|
|
->command(static::$name) |
51
|
|
|
->description('Rollback the last database migration.') |
52
|
|
|
->opt('pretend', 'Dump the SQL queries that would be run.'); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|