Skip to content

Commit

Permalink
Merge pull request #5246 from greg0ire/support-for-collate
Browse files Browse the repository at this point in the history
Add support for collation option to MySQL
  • Loading branch information
greg0ire committed Feb 5, 2022
2 parents cca59b4 + a18ffc1 commit 35eae23
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Platforms/AbstractMySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,12 +452,16 @@ private function buildTableOptions(array $options): string

$tableOptions[] = sprintf('DEFAULT CHARACTER SET %s', $options['charset']);

// Collate
if (! isset($options['collate'])) {
$options['collate'] = $options['charset'] . '_unicode_ci';
if (isset($options['collate'])) {
$options['collation'] = $options['collate'];
}

$tableOptions[] = $this->getColumnCollationDeclarationSQL($options['collate']);
// Collation
if (! isset($options['collation'])) {
$options['collation'] = $options['charset'] . '_unicode_ci';
}

$tableOptions[] = $this->getColumnCollationDeclarationSQL($options['collation']);

// Engine
if (! isset($options['engine'])) {
Expand Down
23 changes: 23 additions & 0 deletions tests/Platforms/MySQLPlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\TransactionIsolationLevel;
use InvalidArgumentException;

Expand All @@ -27,4 +28,26 @@ public function testDropIndexSQLRequiresTable(): void
$this->expectException(InvalidArgumentException::class);
$this->platform->getDropIndexSQL('foo');
}

public function testCollationOptionIsTakenIntoAccount(): void
{
$table = new Table('quotations');
$table->addColumn('id', 'integer');
$table->addOption('collation', 'my_collation');
self::assertStringContainsString(
'my_collation',
$this->platform->getCreateTableSQL($table)[0]
);
}

public function testCollateOptionIsStillSupported(): void
{
$table = new Table('quotations');
$table->addColumn('id', 'integer');
$table->addOption('collate', 'my_collation');
self::assertStringContainsString(
'my_collation',
$this->platform->getCreateTableSQL($table)[0]
);
}
}

0 comments on commit 35eae23

Please sign in to comment.