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