Skip to content

Instantly share code, notes, and snippets.

@EricMcWinNer
Last active November 28, 2021 23:22
Show Gist options
  • Save EricMcWinNer/f1dcfbb92c21553acc531b1d27417df0 to your computer and use it in GitHub Desktop.
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.
<?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