Переход на кодировку utf8md4_unicode_ci

This commit is contained in:
ErickSkrauch 2017-12-23 00:32:36 +03:00
parent 43b69aed0b
commit d2f3a05b31
5 changed files with 44 additions and 7 deletions

View File

@ -9,7 +9,7 @@ variables:
test:backend:
image: docker:latest
services:
- mariadb:10.0
- mariadb:10.2.11
- redis:3.0-alpine
variables:
# mariadb config

View File

@ -11,7 +11,7 @@ class Migration extends YiiMigration {
public function getTableOptions($engine = 'InnoDB') {
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=' . $engine;
$tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=' . $engine;
}
return $tableOptions;

View File

@ -0,0 +1,37 @@
<?php
use console\db\Migration;
class m171222_200114_migrate_to_utf8md4_unicode_ci extends Migration {
public function safeUp() {
$this->execute('SET FOREIGN_KEY_CHECKS=0');
$dbName = $this->db->createCommand('SELECT DATABASE()')->queryScalar();
$this->execute("ALTER DATABASE {{%$dbName}} CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci");
$tables = $this->db->createCommand('SHOW TABLES')->queryColumn();
foreach ($tables as $table) {
$this->execute("ALTER TABLE {{%$table}} CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
}
$this->execute('ALTER TABLE {{%usernames_history}} MODIFY username VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL');
$this->execute('SET FOREIGN_KEY_CHECKS=1');
}
public function safeDown() {
$this->execute('SET FOREIGN_KEY_CHECKS=0');
$dbName = $this->db->createCommand('SELECT DATABASE()')->queryScalar();
$this->execute("ALTER DATABASE {{%$dbName}} CHARACTER SET = utf8 COLLATE = utf8_general_ci");
$tables = $this->db->createCommand('SHOW TABLES')->queryColumn();
foreach ($tables as $table) {
$this->execute("ALTER TABLE {{%$table}} CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci");
}
$this->execute('ALTER TABLE {{%usernames_history}} MODIFY username VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL');
$this->execute('SET FOREIGN_KEY_CHECKS=1');
}
}

View File

@ -1,4 +1,4 @@
FROM mariadb:10.0
FROM mariadb:10.2.11
COPY custom.cnf /etc/mysql/conf.d/

View File

@ -1,9 +1,9 @@
[mysql]
default-character-set = utf8
default-character-set = utf8mb4
[mysqld]
character-set-server = utf8
collation-server = utf8_general_ci
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
[client]
default-character-set = utf8
default-character-set = utf8mb4