DB/MySQL: Use utf8mb4 to support emojis

closes #706 (Allow emoji as private message text)
This commit is contained in:
Igor Scheller 2020-04-07 19:36:48 +02:00 committed by msquare
parent f3af7bab50
commit 055586cb8f
3 changed files with 41 additions and 2 deletions

View File

@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Query\Grammars\MySqlGrammar;
class ChangeMysqlDatabaseEncodingToUtf8mb4 extends Migration
{
/**
* Run the migration
*/
public function up(): void
{
$connection = $this->schema->getConnection();
if (!$connection->getQueryGrammar() instanceof MySqlGrammar) {
return;
}
$connection->unprepared('ALTER DATABASE CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
foreach ($connection->getDoctrineSchemaManager()->listTableNames() as $table) {
$connection->unprepared(
'ALTER TABLE `' . $table . '` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci'
);
}
}
/**
* Reverse the migration
*/
public function down(): void
{
// As utf8mb4 is a superset of utf8, there is nothing to do here
}
}

View File

@ -24,8 +24,8 @@ class DatabaseServiceProvider extends ServiceProvider
'database' => '', 'database' => '',
'username' => '', 'username' => '',
'password' => '', 'password' => '',
'charset' => 'utf8', 'charset' => 'utf8mb4',
'collation' => 'utf8_unicode_ci', 'collation' => 'utf8mb4_unicode_ci',
'timezone' => $now->format('P'), 'timezone' => $now->format('P'),
'prefix' => '', 'prefix' => '',
], $dbConfig)); ], $dbConfig));

View File

@ -45,6 +45,7 @@ trait HasDatabase
['migration' => '2018_01_01_000005_add_angel_supporter_permissions'], ['migration' => '2018_01_01_000005_add_angel_supporter_permissions'],
['migration' => '2018_12_27_000000_fix_missing_arrival_dates'], ['migration' => '2018_12_27_000000_fix_missing_arrival_dates'],
['migration' => '2019_09_07_000000_migrate_admin_schedule_permissions'], ['migration' => '2019_09_07_000000_migrate_admin_schedule_permissions'],
['migration' => '2020_04_07_000000_change_mysql_database_encoding_to_utf8mb4'],
] ]
); );