FEATURE: change collation of all non-utf8_unicode_ci tables
This commit is contained in:
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class ChangeCollationOfTables extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
$data = DB::select('
|
||||||
|
SELECT
|
||||||
|
CONCAT("ALTER TABLE `", TABLE_NAME,"` CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci") AS mySQL
|
||||||
|
FROM INFORMATION_SCHEMA.TABLES
|
||||||
|
WHERE TABLE_SCHEMA="' . env('DB_DATABASE') . '"
|
||||||
|
AND TABLE_COLLATION!="utf8_unicode_ci"
|
||||||
|
AND TABLE_TYPE="BASE TABLE"
|
||||||
|
');
|
||||||
|
|
||||||
|
DB::statement('SET foreign_key_checks = 0');
|
||||||
|
foreach ($data as $query) {
|
||||||
|
DB::statement($query->mySQL);
|
||||||
|
}
|
||||||
|
DB::statement('SET foreign_key_checks = 1');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
// nothing to do
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user