From e08f583c3aff602da2c8b32b746493e9b1bfe22a Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 9 Mar 2017 21:43:53 +0200 Subject: [PATCH] Check for InnoDB engine --- app/Http/Controllers/AppController.php | 16 ++++++++++++++++ docs/update.rst | 2 -- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/AppController.php b/app/Http/Controllers/AppController.php index c9a1d90f8ee5..59104e6452de 100644 --- a/app/Http/Controllers/AppController.php +++ b/app/Http/Controllers/AppController.php @@ -268,6 +268,7 @@ class AppController extends BaseController if (! Utils::isNinjaProd()) { try { set_time_limit(60 * 5); + $this->checkInnoDB(); Artisan::call('clear-compiled'); Artisan::call('cache:clear'); Artisan::call('debugbar:clear'); @@ -303,6 +304,21 @@ class AppController extends BaseController return Redirect::to('/'); } + // MySQL changed the default table type from MyISAM to InnoDB + // We need to make sure all tables are InnoDB to prevent migration failures + public function checkInnoDB() + { + $tables = DB::select('SHOW TABLES'); + $sql = "SET sql_mode = 'ALLOW_INVALID_DATES';\n"; + + foreach($tables as $table) { + $fieldName = 'Tables_in_' . env('DB_DATABASE'); + $sql .= "ALTER TABLE {$table->$fieldName} engine=InnoDB;\n"; + } + + DB::unprepared($sql); + } + public function emailBounced() { $messageId = Input::get('MessageID'); diff --git a/docs/update.rst b/docs/update.rst index a50e8bca80b7..7c390e9628b8 100644 --- a/docs/update.rst +++ b/docs/update.rst @@ -14,8 +14,6 @@ If the auto-update fails you can manually run the update with the following comm php artisan migrate php artisan db:seed --class=UpdateSeeder -We’ve seen some updates fail when moving the app to a new server because the MySQL default storage engine has changed with MySQL 5.7. If you see ``SQLSTATE[HY000]: General error: 1215`` error you may be able to fix it by running this `SQL query `_ - Version 2.6 """""""""""