Skip to content

Commit 4b10cb1

Browse files
committed
Add Migrations.default_collation config option
Allow configuring a global default collation for MySQL tables via Configure::read('Migrations.default_collation'). When null (default), tables inherit the database server collation. Per-table collation options still take precedence.
1 parent c6f2b0d commit 4b10cb1

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

config/app.example.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
'unsigned_primary_keys' => null, // Default false
1010
'unsigned_ints' => null, // Default false, make sure this is aligned with the above config
1111
'column_null_default' => null, // Default false
12+
'default_collation' => null, // Default null (uses database collation). Set to e.g. 'utf8mb4_unicode_ci' to override.
1213
],
1314
];

src/Db/Adapter/MysqlAdapter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@ public function createTable(TableMetadata $table, array $columns = [], array $in
253253
'engine' => 'InnoDB',
254254
];
255255

256+
$collation = Configure::read('Migrations.default_collation');
257+
if ($collation) {
258+
$defaultOptions['collation'] = $collation;
259+
}
260+
256261
$options = array_merge(
257262
$defaultOptions,
258263
array_intersect_key($this->getOptions(), $defaultOptions),

0 commit comments

Comments
 (0)