49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands\Modules;
|
|
|
|
use App\Models\Module;
|
|
use Illuminate\Console\Command;
|
|
|
|
class RunMigrations extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
* @var string
|
|
*/
|
|
protected $signature = 'module:migrate {module?} {--rollback : Rollback one migration}';
|
|
/**
|
|
* The console command description.
|
|
* @var string
|
|
*/
|
|
protected $description = 'Run migrations for all modules or for one module';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
$modules = Module::where('enabled', true);
|
|
if (!is_null($module = $this->argument('module'))) {
|
|
$modules = $modules->where('static_name', $module);
|
|
}
|
|
$modules = $modules->get();
|
|
|
|
if ($modules->isEmpty()) {
|
|
$this->error('No valid modules.');
|
|
return;
|
|
}
|
|
|
|
$command = $this->option('rollback') ? 'migrate:rollback' : 'migrate';
|
|
foreach ($modules as $module) {
|
|
$this->info('Migrating '.$module->static_name);
|
|
|
|
$basePath = $module->is_template ? config('modules.path.template') : config('modules.paths.modules');
|
|
$path = $basePath . '/' . $module->static_name . '/Database/Migrations/';
|
|
|
|
$this->call($command, ['--path' => $path]);
|
|
}
|
|
}
|
|
}
|