Last active
November 28, 2021 23:22
-
-
Save EricMcWinNer/f1dcfbb92c21553acc531b1d27417df0 to your computer and use it in GitHub Desktop.
A simple migration that allows us convert all the tables in our database to the InnoDB engine.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Migrations\Migration; | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Support\Facades\Schema; | |
class CovertAllTablesEngineToInnodb extends Migration | |
{ | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
$currentDB = config('database.connections.mysql.database'); | |
$tables = DB::select('SHOW TABLES'); | |
foreach($tables as $table) { | |
DB::statement('ALTER TABLE ' . $table->{"Tables_in_" . $currentDB} . ' ENGINE = InnoDB'); | |
} | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
$currentDB = config('database.connections.mysql.database'); | |
$tables = DB::select('SHOW TABLES'); | |
foreach($tables as $table) { | |
DB::statement('ALTER TABLE ' . $table->{"Tables_in_" . $currentDB} . ' ENGINE = MyISAM'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment