FEATURE #2520: add commands for creating new migration and running migrations in modules

This commit is contained in:
Michal Kváček
2017-09-01 23:25:26 +02:00
parent c92ba41def
commit a5b6f6fa0d
22 changed files with 173 additions and 3 deletions
@@ -0,0 +1,48 @@
<?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]);
}
}
}