mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Migration fixes (#9776)
* add migrate:install to lnms, but hide it * Fix Database migration validation * remove extra import * Don't allow install to continue if db build fails
This commit is contained in:
@@ -27,6 +27,7 @@ namespace LibreNMS\DB;
|
||||
|
||||
use LibreNMS\Config;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
use \Schema as LaravelSchema;
|
||||
|
||||
class Schema
|
||||
{
|
||||
@@ -39,6 +40,51 @@ class Schema
|
||||
private $relationships;
|
||||
private $schema;
|
||||
|
||||
/**
|
||||
* Check the database to see if the migrations have all been run
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isCurrent()
|
||||
{
|
||||
if (LaravelSchema::hasTable('migrations')) {
|
||||
return self::getMigrationFiles()->diff(self::getAppliedMigrations())->isEmpty();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for extra migrations and return them
|
||||
*
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public static function getUnexpectedMigrations()
|
||||
{
|
||||
return self::getAppliedMigrations()->diff(self::getMigrationFiles());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
private static function getMigrationFiles()
|
||||
{
|
||||
$migrations = collect(glob(base_path('database/migrations/') . '*.php'))
|
||||
->map(function ($migration_file) {
|
||||
return basename($migration_file, '.php');
|
||||
});
|
||||
return $migrations;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
private static function getAppliedMigrations()
|
||||
{
|
||||
$db = Eloquent::DB()->table('migrations')->pluck('migration');
|
||||
return $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the primary key column(s) for a table
|
||||
*
|
||||
|
Reference in New Issue
Block a user