mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Use Laravel schema migration command directly (#14039)
* Add new schema migration command * Apply fixes from StyleCI
This commit is contained in:
@@ -42,28 +42,15 @@ class CheckDatabaseSchemaVersion implements Validation, ValidationFixer
|
||||
public function validate(): ValidationResult
|
||||
{
|
||||
self::$current = false;
|
||||
$current = \LibreNMS\DB\Schema::getLegacySchema();
|
||||
$latest = 1000;
|
||||
|
||||
if ($current === 0 || $current === $latest) {
|
||||
// Using Laravel migrations
|
||||
if (! Schema::isCurrent()) {
|
||||
return ValidationResult::fail(trans('validation.validations.database.CheckSchemaVersion.fail_outdated'), './lnms migrate')
|
||||
->setFixer(__CLASS__);
|
||||
}
|
||||
if (! Schema::isCurrent()) {
|
||||
return ValidationResult::fail(trans('validation.validations.database.CheckSchemaVersion.fail_outdated'), './lnms migrate')
|
||||
->setFixer(__CLASS__);
|
||||
}
|
||||
|
||||
$migrations = Schema::getUnexpectedMigrations();
|
||||
if ($migrations->isNotEmpty()) {
|
||||
return ValidationResult::warn(trans('validation.validations.database.CheckSchemaVersion.warn_extra_migrations', ['migrations' => $migrations->implode(', ')]));
|
||||
}
|
||||
} elseif ($current < $latest) {
|
||||
return ValidationResult::fail(
|
||||
trans('validation.validations.database.CheckSchemaVersion.fail_legacy_outdated', ['current' => $current, 'latest' => $latest]),
|
||||
trans('validation.validations.database.CheckSchemaVersion.fix_legacy_outdated'),
|
||||
);
|
||||
} else {
|
||||
// latest > current
|
||||
return ValidationResult::warn(trans('validation.validations.database.CheckSchemaVersion.warn_legacy_newer'));
|
||||
$migrations = Schema::getUnexpectedMigrations();
|
||||
if ($migrations->isNotEmpty()) {
|
||||
return ValidationResult::warn(trans('validation.validations.database.CheckSchemaVersion.warn_extra_migrations', ['migrations' => $migrations->implode(', ')]));
|
||||
}
|
||||
|
||||
self::$current = true;
|
||||
@@ -90,6 +77,6 @@ class CheckDatabaseSchemaVersion implements Validation, ValidationFixer
|
||||
|
||||
public function fix(): bool
|
||||
{
|
||||
return \Artisan::call('migrate', ['--force' => true]) === 0;
|
||||
return \Artisan::call('migrate', ['--force' => true, '--isolated' => true]) === 0;
|
||||
}
|
||||
}
|
||||
|
@@ -93,7 +93,7 @@ class CheckSchemaCollation implements Validation, ValidationFixer
|
||||
public function fix(): bool
|
||||
{
|
||||
\DB::table('migrations')->where('migration', '2021_02_09_122930_migrate_to_utf8mb4')->delete();
|
||||
$res = \Artisan::call('migrate', ['--force' => true]);
|
||||
$res = \Artisan::call('migrate', ['--force' => true, '--isolated' => true]);
|
||||
|
||||
return $res === 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user