|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Rawilk\LaravelModules\Commands\Other; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
6
|
|
|
use Rawilk\LaravelModules\Migrations\Migrator; |
|
7
|
|
|
|
|
8
|
|
|
class MigrateResetCommand extends Command |
|
9
|
|
|
{ |
|
10
|
|
|
/** @var string */ |
|
11
|
|
|
protected $signature = 'module:migrate-reset |
|
12
|
|
|
{module? : The module to reset migrations for} |
|
13
|
|
|
{--d|direction=desc : The direction to sort modules in} |
|
14
|
|
|
{--force : Force the operation to run when in production} |
|
15
|
|
|
{--pretend : Dump the SQL queries that would be run}'; |
|
16
|
|
|
|
|
17
|
|
|
/** @var string */ |
|
18
|
|
|
protected $description = 'Reset migrations for the specified module.'; |
|
19
|
|
|
|
|
20
|
|
|
/** @var \Rawilk\LaravelModules\Contracts\Repository */ |
|
21
|
|
|
protected $module; |
|
22
|
|
|
|
|
23
|
|
|
public function handle(): void |
|
24
|
|
|
{ |
|
25
|
|
|
$this->module = $this->laravel['modules']; |
|
26
|
|
|
|
|
27
|
|
|
if ($name = $this->argument('module')) { |
|
28
|
|
|
$this->reset($name); |
|
29
|
|
|
|
|
30
|
|
|
return; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** @var \Rawilk\LaravelModules\Module $module */ |
|
34
|
|
|
foreach ($this->module->getOrdered($this->option('direction')) as $module) { |
|
35
|
|
|
$this->line("Resetting migrations for module: <info>{$module->getName()}</info>"); |
|
36
|
|
|
|
|
37
|
|
|
$this->reset($module); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
private function reset($module): void |
|
42
|
|
|
{ |
|
43
|
|
|
if (is_string($module)) { |
|
44
|
|
|
$module = $this->module->findOrFail($module); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$migrator = new Migrator($module, $this->getLaravel()); |
|
48
|
|
|
|
|
49
|
|
|
if ($database = $this->option('database')) { |
|
50
|
|
|
$migrator->setDatabase($database); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$migrated = $migrator->reset(); |
|
54
|
|
|
|
|
55
|
|
|
if (count($migrated) > 0) { |
|
56
|
|
|
foreach ($migrated as $migration) { |
|
57
|
|
|
$this->line("Migration rolled back: <info>{$migration}</info>"); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$this->comment('Nothing to rollback.'); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|