mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fix schema validation and os def cache invalidation (#9789)
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
namespace LibreNMS\DB;
|
namespace LibreNMS\DB;
|
||||||
|
|
||||||
use LibreNMS\Config;
|
use LibreNMS\Config;
|
||||||
|
use LibreNMS\Util\Version;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
use \Schema as LaravelSchema;
|
use \Schema as LaravelSchema;
|
||||||
|
|
||||||
@@ -81,8 +82,7 @@ class Schema
|
|||||||
*/
|
*/
|
||||||
private static function getAppliedMigrations()
|
private static function getAppliedMigrations()
|
||||||
{
|
{
|
||||||
$db = Eloquent::DB()->table('migrations')->pluck('migration');
|
return Eloquent::DB()->table('migrations')->pluck('migration');
|
||||||
return $db;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,10 +147,11 @@ class Schema
|
|||||||
{
|
{
|
||||||
$update_cache = true;
|
$update_cache = true;
|
||||||
$cache_file = Config::get('install_dir') . "/cache/{$base}_relationships.cache";
|
$cache_file = Config::get('install_dir') . "/cache/{$base}_relationships.cache";
|
||||||
|
$db_version = Version::get()->database();
|
||||||
|
|
||||||
if (is_file($cache_file)) {
|
if (is_file($cache_file)) {
|
||||||
$cache = unserialize(file_get_contents($cache_file));
|
$cache = unserialize(file_get_contents($cache_file));
|
||||||
if ($cache['version'] == get_db_schema()) {
|
if ($cache['version'] == $db_version) {
|
||||||
$update_cache = false; // cache is valid skip update
|
$update_cache = false; // cache is valid skip update
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,7 +166,7 @@ class Schema
|
|||||||
}
|
}
|
||||||
|
|
||||||
$cache = [
|
$cache = [
|
||||||
'version' => get_db_schema(),
|
'version' => $db_version,
|
||||||
$base => $paths
|
$base => $paths
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@@ -50,12 +50,14 @@ class Database extends BaseValidation
|
|||||||
$latest = 1000;
|
$latest = 1000;
|
||||||
|
|
||||||
if ($current === 0 || $current === $latest) {
|
if ($current === 0 || $current === $latest) {
|
||||||
|
// Using Laravel migrations
|
||||||
if (!Schema::isCurrent()) {
|
if (!Schema::isCurrent()) {
|
||||||
$validator->fail("Your database is out of date!", './lnms migrate');
|
$validator->fail("Your database is out of date!", './lnms migrate');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($migrations = Schema::getUnexpectedMigrations()) {
|
$migrations = Schema::getUnexpectedMigrations();
|
||||||
|
if ($migrations->isNotEmpty()) {
|
||||||
$validator->warn("Your database schema has extra migrations (" . $migrations->implode(', ') .
|
$validator->warn("Your database schema has extra migrations (" . $migrations->implode(', ') .
|
||||||
"). If you just switched to the stable release from the daily release, your database is in between releases and this will be resolved with the next release.");
|
"). If you just switched to the stable release from the daily release, your database is in between releases and this will be resolved with the next release.");
|
||||||
}
|
}
|
||||||
|
@@ -2521,18 +2521,6 @@ function get_db_schema()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the database schema is up to date.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
function db_schema_is_current()
|
|
||||||
{
|
|
||||||
$current = get_db_schema();
|
|
||||||
|
|
||||||
return $current >= 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $device
|
* @param $device
|
||||||
* @return int|null
|
* @return int|null
|
||||||
|
Reference in New Issue
Block a user