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:
Tony Murray
2019-02-05 16:50:51 -06:00
committed by GitHub
parent 49f206f58e
commit e5eb32c4a9
5 changed files with 103 additions and 3 deletions

View File

@@ -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
*