Validate schema in utc (#13182)

if timestamp is off, prepend sql query to set UTC for session
This commit is contained in:
Tony Murray
2021-08-30 11:02:48 -05:00
committed by GitHub
parent 9a635232dc
commit e81ee98b31
2 changed files with 7 additions and 0 deletions

View File

@@ -346,6 +346,8 @@ class Schema
$output = [];
$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) {
$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) {

View File

@@ -319,6 +319,11 @@ class Database extends BaseValidation
$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)) {
$validator->ok('Database schema correct');
} else {