|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Consigliere\Components\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command as ComponentCommand; |
|
6
|
|
|
use Consigliere\Components\Migrations\Migrator; |
|
7
|
|
|
use Consigliere\Components\Component; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
10
|
|
|
|
|
11
|
|
|
class MigrateCommand extends ComponentCommand |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* The console command name. |
|
15
|
|
|
* |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $name = 'component:migrate'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* The console command description. |
|
22
|
|
|
* |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $description = 'Migrate the migrations from the specified component or from all components.'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var \Consigliere\Components\Repository |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $component; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Execute the console command. |
|
34
|
|
|
* |
|
35
|
|
|
* @return mixed |
|
36
|
|
|
*/ |
|
37
|
|
|
public function fire() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->component = $this->laravel['components']; |
|
40
|
|
|
|
|
41
|
|
|
$name = $this->argument('component'); |
|
42
|
|
|
|
|
43
|
|
|
if ($name) { |
|
44
|
|
|
$component = $this->component->findOrFail($name); |
|
45
|
|
|
|
|
46
|
|
|
return $this->migrate($component); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
foreach ($this->component->getOrdered($this->option('direction')) as $component) { |
|
50
|
|
|
$this->line('Running for component: <info>' . $component->getName() . '</info>'); |
|
51
|
|
|
|
|
52
|
|
|
$this->migrate($component); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Run the migration from the specified component. |
|
58
|
|
|
* |
|
59
|
|
|
* @param Component $component |
|
60
|
|
|
* |
|
61
|
|
|
* @return mixed |
|
62
|
|
|
*/ |
|
63
|
|
|
protected function migrate(Component $component) |
|
64
|
|
|
{ |
|
65
|
|
|
$path = str_replace(base_path(), '', (new Migrator($component))->getPath()); |
|
66
|
|
|
$this->call('migrate', [ |
|
67
|
|
|
'--path' => $path, |
|
68
|
|
|
'--database' => $this->option('database'), |
|
69
|
|
|
'--pretend' => $this->option('pretend'), |
|
70
|
|
|
'--force' => $this->option('force'), |
|
71
|
|
|
]); |
|
72
|
|
|
|
|
73
|
|
|
if ($this->option('seed')) { |
|
74
|
|
|
$this->call('component:seed', ['component' => $component->getName()]); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Get the console command arguments. |
|
80
|
|
|
* |
|
81
|
|
|
* @return array |
|
82
|
|
|
*/ |
|
83
|
|
|
protected function getArguments() |
|
84
|
|
|
{ |
|
85
|
|
|
return [ |
|
86
|
|
|
['component', InputArgument::OPTIONAL, 'The name of component will be used.'], |
|
87
|
|
|
]; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Get the console command options. |
|
92
|
|
|
* |
|
93
|
|
|
* @return array |
|
94
|
|
|
*/ |
|
95
|
|
|
protected function getOptions() |
|
96
|
|
|
{ |
|
97
|
|
|
return [ |
|
98
|
|
|
['direction', 'd', InputOption::VALUE_OPTIONAL, 'The direction of ordering.', 'asc'], |
|
99
|
|
|
['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'], |
|
100
|
|
|
['pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'], |
|
101
|
|
|
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'], |
|
102
|
|
|
['seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'], |
|
103
|
|
|
]; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|