Fix installer when DB is empty (#12873)

(which is every time)
This commit is contained in:
Tony Murray
2021-05-13 13:02:43 -05:00
committed by GitHub
parent 5ba3df45eb
commit 77a17dac88
2 changed files with 19 additions and 7 deletions

View File

@@ -50,12 +50,24 @@ class Database extends BaseValidation
return; return;
} }
$this->validateSystem($validator);
if ($this->checkSchemaVersion($validator)) {
$this->checkSchema($validator);
$this->checkCollation($validator);
}
}
public function validateSystem(Validator $validator)
{
$this->checkVersion($validator); $this->checkVersion($validator);
$this->checkMode($validator); $this->checkMode($validator);
$this->checkTime($validator); $this->checkTime($validator);
$this->checkMysqlEngine($validator); $this->checkMysqlEngine($validator);
}
// check database schema version private function checkSchemaVersion(Validator $validator): bool
{
$current = \LibreNMS\DB\Schema::getLegacySchema(); $current = \LibreNMS\DB\Schema::getLegacySchema();
$latest = 1000; $latest = 1000;
@@ -64,7 +76,7 @@ class Database extends BaseValidation
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 false;
} }
$migrations = Schema::getUnexpectedMigrations(); $migrations = Schema::getUnexpectedMigrations();
@@ -78,13 +90,12 @@ class Database extends BaseValidation
'Manually run ./daily.sh, and check for any errors.' 'Manually run ./daily.sh, and check for any errors.'
); );
return; return false;
} elseif ($current > $latest) { } elseif ($current > $latest) {
$validator->warn("Your database schema ($current) is newer than expected ($latest). 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."); $validator->warn("Your database schema ($current) is newer than expected ($latest). 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.");
} }
$this->checkCollation($validator); return true;
$this->checkSchema($validator);
} }
private function checkVersion(Validator $validator) private function checkVersion(Validator $validator)

View File

@@ -31,6 +31,7 @@ use LibreNMS\DB\Eloquent;
use LibreNMS\DB\Schema; use LibreNMS\DB\Schema;
use LibreNMS\Interfaces\InstallerStep; use LibreNMS\Interfaces\InstallerStep;
use LibreNMS\ValidationResult; use LibreNMS\ValidationResult;
use LibreNMS\Validations\Database;
use LibreNMS\Validator; use LibreNMS\Validator;
use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\HttpFoundation\StreamedResponse;
@@ -75,7 +76,7 @@ class DatabaseController extends InstallationController implements InstallerStep
// validate Database // validate Database
$validator = new Validator(); $validator = new Validator();
$validator->validate(['database']); (new Database())->validateSystem($validator);
$results = $validator->getResults('database'); $results = $validator->getResults('database');
/** @var \LibreNMS\ValidationResult $result */ /** @var \LibreNMS\ValidationResult $result */