Skip to content

Commit a3a8f9f

Browse files
committed
AC-9755:Set default collation to utf8mb4 for MySQL
1 parent 31fb7d5 commit a3a8f9f

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface, Rese
144144
*/
145145
private $isMysql8Engine;
146146

147+
/***
148+
* const for column type
149+
*/
150+
private const COLUMN_TYPE = ['varchar', 'char', 'text', 'mediumtext', 'longtext'];
151+
147152
/**
148153
* MySQL column - Table DDL type pairs
149154
*
@@ -257,7 +262,7 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface, Rese
257262
* @var string
258263
*/
259264
private $mysqlversion;
260-
265+
261266
/**
262267
* Constructor
263268
*
@@ -2429,6 +2434,19 @@ protected function _getColumnsDefinition(Table $table)
24292434
);
24302435
}
24312436

2437+
if(count($definition)) {
2438+
foreach ($definition as $index => $columnDefinition) {
2439+
$type = explode(' ', trim($columnDefinition));
2440+
$pattern = '/\b(' . implode('|', array_map('preg_quote', self::COLUMN_TYPE)) . ')\b/i';
2441+
if (preg_match($pattern, $type[1]) === 1) {
2442+
$charsets = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci';
2443+
$columnsAttribute = explode(' ', trim($columnDefinition));
2444+
array_splice($columnsAttribute, 2, 0, $charsets);
2445+
$definition[$index] = implode(' ', $columnsAttribute);
2446+
}
2447+
}
2448+
}
2449+
24322450
// PRIMARY KEY
24332451
if (!empty($primary)) {
24342452
asort($primary, SORT_NUMERIC);

setup/src/Magento/Setup/Model/Installer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ class Installer
277277
/***
278278
* charset and collation for column level
279279
*/
280-
private const COLUMN_ENCODING = ""; //CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci";
280+
private const COLUMN_ENCODING = " CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci";
281281

282282
/**
283283
* Constructor

0 commit comments

Comments
 (0)