From cbd423397f236c7140394cf74e30850272f66f0d Mon Sep 17 00:00:00 2001 From: Vitalii Bezsheiko Date: Tue, 14 Feb 2023 15:53:00 +0200 Subject: [PATCH 1/2] pkp/pkp-lib#6732 Preflight check of database engine --- .../v3_4_0/PreflightCheckMigration.php | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/classes/migration/upgrade/v3_4_0/PreflightCheckMigration.php b/classes/migration/upgrade/v3_4_0/PreflightCheckMigration.php index 50cbba48ca2..34b00f8386e 100755 --- a/classes/migration/upgrade/v3_4_0/PreflightCheckMigration.php +++ b/classes/migration/upgrade/v3_4_0/PreflightCheckMigration.php @@ -15,6 +15,7 @@ use APP\core\Application; use Exception; +use Illuminate\Database\MySqlConnection; use Illuminate\Database\PostgresConnection; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; @@ -550,6 +551,31 @@ public function up(): void throw new \Exception('A row with setting_name="submissionChecklist" found in table ' . $this->getContextSettingsTable() . " without the expected setting_value. Expected an array encoded in JSON but found:\n\n" . $value . "\n\nFix or remove this row before upgrading."); } }); + + // Check if database engine supports foreign key constraints, see pkp/pkp-lib#6732 + if (DB::connection() instanceof MySqlConnection) { + $defaultEngine = DB::scalar('SELECT ENGINE FROM INFORMATION_SCHEMA.ENGINES WHERE SUPPORT = "DEFAULT"'); + if ($defaultEngine !== 'InnoDB') { + throw new Exception( + 'A default database engine ' . $defaultEngine . ' isn\'t supported, expecting InnoDB. ' . + 'Please change the default database engine to InnoDB to run the upgrade.' + ); + } + + $result = DB::select( + 'SELECT t.table_name, t.engine AS table_engine + FROM information_schema.tables AS t + WHERE t.table_schema = :databaseName AND t.engine <> "InnoDB"', + ['databaseName' => DB::connection()->getDatabaseName()] + ); + + if (count($result) > 0) { + throw new Exception( + 'Storage engine that doesn\'t support foreign key constraints detected in one or more tables. ' . + 'Change to InnoDB before running the upgrade.' + ); + } + } } catch (Throwable $e) { if ($fallbackVersion = $this->setFallbackVersion()) { $this->_installer->log("A pre-flight check failed. The software was successfully upgraded to ${fallbackVersion} but could not be upgraded further (to " . $this->_installer->newVersion->getVersionString() . '). Check and correct the error, then try again.'); From 41554d06d37078ac8f4ab90af050a073ae4da7b6 Mon Sep 17 00:00:00 2001 From: Vitalii Bezsheiko Date: Wed, 15 Feb 2023 20:34:27 +0200 Subject: [PATCH 2/2] pkp/pkp-lib#6732 List tables with unsupported storage engine --- classes/migration/upgrade/v3_4_0/PreflightCheckMigration.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/classes/migration/upgrade/v3_4_0/PreflightCheckMigration.php b/classes/migration/upgrade/v3_4_0/PreflightCheckMigration.php index 34b00f8386e..82d00eff07b 100755 --- a/classes/migration/upgrade/v3_4_0/PreflightCheckMigration.php +++ b/classes/migration/upgrade/v3_4_0/PreflightCheckMigration.php @@ -570,9 +570,10 @@ public function up(): void ); if (count($result) > 0) { + $tableNames = data_get($result, '*.TABLE_NAME'); throw new Exception( - 'Storage engine that doesn\'t support foreign key constraints detected in one or more tables. ' . - 'Change to InnoDB before running the upgrade.' + 'Storage engine that doesn\'t support foreign key constraints detected in one or more tables: ' . + implode(', ', $tableNames) . '. Change to InnoDB before running the upgrade.' ); } }