Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Db/Adapter/MysqlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,13 @@ public function createTable(Table $table, array $columns = [], array $indexes =
*/
protected function mapColumnData(array $data): array
{
// Convert uuid to char(36) to ensure collation support.
// The dialect only adds COLLATE for text, char, and string types.
if ($data['type'] === self::PHINX_TYPE_UUID) {
$data['type'] = 'char';
$data['length'] = 36;
}

if ($data['type'] == self::PHINX_TYPE_TEXT && $data['length'] !== null) {
$data['length'] = match ($data['length']) {
self::TEXT_LONG => TableSchema::LENGTH_LONG,
Expand Down
23 changes: 23 additions & 0 deletions tests/TestCase/Db/Adapter/MysqlAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,29 @@ public function testCreateTable()
$this->assertFalse($columns[0]->isSigned());
}

public function testCreateTableWithColumnCollation()
{
$table = new Table\Table('custom_collation', ['id' => false, 'primary_key' => ['id'], 'collation' => 'utf8mb4_unicode_ci']);

$columnId = new Column();
$columnId
->setName('id')
->setType('uuid')
->setCollation('ascii_general_ci')
->setEncoding('ascii');
$columnName = new Column();
$columnName
->setName('name')
->setType('text');
$columns = [$columnId, $columnName];

$this->adapter->createTable($table, $columns);

$rows = $this->adapter->fetchAll('SHOW FULL COLUMNS FROM custom_collation');
$this->assertEquals('ascii_general_ci', $rows[0]['Collation']); // specified collation is set
$this->assertEquals('utf8mb4_unicode_ci', $rows[1]['Collation']); // if not specified uses table's collation
}

public function testCreateTableWithComment()
{
$tableComment = 'Table comment';
Expand Down