Browse Source

Make utf8mb4_bin the default collation for MySQL and migrate all the existing tables

pull/1185/head
Timothée Jaussoin 3 years ago
parent
commit
de02548346
  1. 1
      CHANGELOG.md
  2. 2
      database/migrations/20230318150507_set_correct_collation_emoji_to_reactions_table.php
  3. 29
      database/migrations/20230321201405_set_correct_collation_to_all_tables.php
  4. 2
      src/Movim/Bootstrap.php

1
CHANGELOG.md

@ -46,6 +46,7 @@ v0.21 (trunk)
* Drop the outdated FromModlToEloquent migration script
* Remove the Bookmark synchronization feature, the server is taking care of it
* Implement XEP-0469: Bookmark Pinning
* Make utf8mb4_bin the default collation for MySQL and migrate all the existing tables
v0.20
---------------------------

2
database/migrations/20230318150507_set_correct_collation_emoji_to_reactions_table.php

@ -11,7 +11,7 @@ class SetCorrectCollationEmojiToReactionsTable extends Migration
* See https://github.com/movim/movim/issues/1042
*/
if ($this->schema->getConnection()->getDriverName() == 'mysql') {
$this->schema->getConnection()->unprepared('alter table reactions modify emoji varchar(32) charset utf8mb4 collate utf8mb4_bin;');
$this->schema->getConnection()->unprepared('alter table reactions modify emoji varchar(32) charset utf8mb4 collate utf8mb4_bin;');
}
}

29
database/migrations/20230321201405_set_correct_collation_to_all_tables.php

@ -0,0 +1,29 @@
<?php
use Movim\Migration;
class SetCorrectCollationToAllTables extends Migration
{
public function up()
{
if ($this->schema->getConnection()->getDriverName() == 'mysql') {
$this->disableForeignKeyCheck();
foreach ($this->schema->getConnection()->select('
select concat("ALTER TABLE `", TABLE_NAME,"` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;") as result
from information_schema.tables
where table_schema="' . config('database.database') . '"
and table_type="BASE TABLE"
') as $convert) {
$this->schema->getConnection()->statement($convert->result);
};
$this->enableForeignKeyCheck();
}
}
public function down()
{
}
}

2
src/Movim/Bootstrap.php

@ -146,7 +146,7 @@ class Bootstrap
'username' => config('database.username'),
'password' => config('database.password'),
'charset' => (config('database.driver') == 'mysql') ? 'utf8mb4' : 'utf8',
'collation' => (config('database.driver') == 'mysql') ? 'utf8mb4_unicode_ci' : 'utf8_unicode_ci',
'collation' => (config('database.driver') == 'mysql') ? 'utf8mb4_bin' : 'utf8_unicode_ci',
]);
/**

Loading…
Cancel
Save