Trap migration error for modules if they don't exist

This commit is contained in:
Nabeel Shahzad 2021-05-27 16:14:13 -04:00
parent 5b10dca868
commit a9e5554dea
2 changed files with 14 additions and 6 deletions

View File

@ -77,7 +77,7 @@ class MigrationService extends Service
* Run all of the migrations that are available. Just call artisan since * Run all of the migrations that are available. Just call artisan since
* it looks into all of the module directories, etc * it looks into all of the module directories, etc
*/ */
public function runAllMigrations() public function runAllMigrations(): string
{ {
// A little ugly, run the main migration first, this makes sure the migration table is there // A little ugly, run the main migration first, this makes sure the migration table is there
$output = ''; $output = '';
@ -92,10 +92,14 @@ class MigrationService extends Service
$migrator = $this->getMigrator(); $migrator = $this->getMigrator();
$availMigrations = $this->migrationsAvailable(); $availMigrations = $this->migrationsAvailable();
Log::info('Running '.count($availMigrations).' available migrations'); if (count($availMigrations) > 0) {
$ret = $migrator->run($availMigrations); Log::info('Running '.count($availMigrations).' available migrations');
Log::info('Ran '.count($ret).' migrations'); $ret = $migrator->run($availMigrations);
Log::info('Ran '.count($ret).' migrations');
return $output."\n".implode("\n", $ret); return $output."\n".implode("\n", $ret);
}
return $output;
} }
} }

View File

@ -126,7 +126,11 @@ class ModuleService extends Service
'enabled' => 1, 'enabled' => 1,
]); ]);
Artisan::call('module:migrate '.$module_name, ['--force' => true]); try {
Artisan::call('module:migrate '.$module_name, ['--force' => true]);
} catch (Exception $e) {
Log::error('Error running migration for '.$module_name.'; error='.$e);
}
return true; return true;
} }