mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Validate schema in utc (#13182)
if timestamp is off, prepend sql query to set UTC for session
This commit is contained in:
@@ -346,6 +346,8 @@ class Schema
|
|||||||
$output = [];
|
$output = [];
|
||||||
$db_name = DB::connection($connection)->getDatabaseName();
|
$db_name = DB::connection($connection)->getDatabaseName();
|
||||||
|
|
||||||
|
DB::statement("SET TIME_ZONE='+00:00'"); // set timezone to UTC to avoid timezone issues
|
||||||
|
|
||||||
foreach (DB::connection($connection)->select(DB::raw("SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = '$db_name' ORDER BY TABLE_NAME;")) as $table) {
|
foreach (DB::connection($connection)->select(DB::raw("SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = '$db_name' ORDER BY TABLE_NAME;")) as $table) {
|
||||||
$table = $table->TABLE_NAME;
|
$table = $table->TABLE_NAME;
|
||||||
foreach (DB::connection($connection)->select(DB::raw("SELECT COLUMN_NAME, COLUMN_TYPE, IS_NULLABLE, COLUMN_DEFAULT, EXTRA FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '$db_name' AND TABLE_NAME='$table' ORDER BY ORDINAL_POSITION")) as $data) {
|
foreach (DB::connection($connection)->select(DB::raw("SELECT COLUMN_NAME, COLUMN_TYPE, IS_NULLABLE, COLUMN_DEFAULT, EXTRA FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '$db_name' AND TABLE_NAME='$table' ORDER BY ORDINAL_POSITION")) as $data) {
|
||||||
|
@@ -319,6 +319,11 @@ class Database extends BaseValidation
|
|||||||
$schema_update[] = $this->dropTableSql($table);
|
$schema_update[] = $this->dropTableSql($table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set utc timezone if timestamp issues
|
||||||
|
if (preg_grep('/\d{4}-\d\d-\d\d \d\d:\d\d:\d\d/', $schema_update)) {
|
||||||
|
array_unshift($schema_update, "SET TIME_ZONE='+00:00';");
|
||||||
|
}
|
||||||
|
|
||||||
if (empty($schema_update)) {
|
if (empty($schema_update)) {
|
||||||
$validator->ok('Database schema correct');
|
$validator->ok('Database schema correct');
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user