DB/MySQL: Use utf8mb4 to support emojis

closes #706 (Allow emoji as private message text)
main
Igor Scheller 5 years ago committed by msquare
parent f3af7bab50
commit 055586cb8f

@ -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
}
}

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

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

Loading…
Cancel
Save