Skip to content

Commit

Permalink
Merge branch '3.8.x' into 3.9.x
Browse files Browse the repository at this point in the history
* 3.8.x:
  Fix MariaDB fetching of default table character-set (doctrine#6361) (doctrine#6425)
  Fix the portability documentation (doctrine#6429)
  Update tests/Platforms/AbstractPlatformTestCase.php
  Update tests/Platforms/AbstractPlatformTestCase.php
  add test
  Fix: Skip type comparison if disableTypeComments is true
  • Loading branch information
derrabus committed Jun 7, 2024
2 parents f375b44 + 4aa9cf9 commit df1bd13
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
13 changes: 7 additions & 6 deletions docs/en/reference/portability.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,16 @@ Using the following code block in your initialization will:
<?php
use Doctrine\DBAL\ColumnCase;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Portability\Connection as PortableConnection;
use Doctrine\DBAL\Portability\Middleware as PotableMiddleware;
$params = [
// vendor specific configuration
$configuration = new Configuration();
$configuration->setMiddlewares([
// Other middlewares
//...
'wrapperClass' => PortableConnection::class,
'portability' => PortableConnection::PORTABILITY_ALL,
'fetch_case' => ColumnCase::LOWER,
];
new PortableMiddleware(PortableConnection::PORTABILITY_ALL, ColumnCase::LOWER),
]);
This sort of portability handling is pretty expensive because all the result
rows and columns have to be looped inside PHP before being returned to you.
Expand Down
5 changes: 5 additions & 0 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -4693,6 +4693,11 @@ public function columnsEqual(Column $column1, Column $column2): bool
return false;
}

// If disableTypeComments is true, we do not need to check types, all comparison is already done above
if ($this->disableTypeComments) {
return true;
}

return $column1->getType() === $column2->getType();
}

Expand Down
8 changes: 7 additions & 1 deletion src/Schema/MySQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,11 @@ protected function selectForeignKeyColumns(string $databaseName, ?string $tableN
*/
protected function fetchTableOptionsByTable(string $databaseName, ?string $tableName = null): array
{
// MariaDB-10.10.1 added FULL_COLLATION_NAME to the information_schema.COLLATION_CHARACTER_SET_APPLICABILITY.
// A base collation like uca1400_ai_ci can refer to multiple character sets. The value in the
// information_schema.TABLES.TABLE_COLLATION corresponds to the full collation name.
// The MariaDB executable comment syntax with version, /*M!101001, is exclusively executed on
// MariaDB-10.10.1+ servers for backwards compatibility, and compatiblity to MySQL servers.
$sql = <<<'SQL'
SELECT t.TABLE_NAME,
t.ENGINE,
Expand All @@ -567,7 +572,8 @@ protected function fetchTableOptionsByTable(string $databaseName, ?string $table
ccsa.CHARACTER_SET_NAME
FROM information_schema.TABLES t
INNER JOIN information_schema.COLLATION_CHARACTER_SET_APPLICABILITY ccsa
ON ccsa.COLLATION_NAME = t.TABLE_COLLATION
ON /*M!101001 ccsa.FULL_COLLATION_NAME = t.TABLE_COLLATION OR */
ccsa.COLLATION_NAME = t.TABLE_COLLATION
SQL;

$conditions = ['t.TABLE_SCHEMA = ?'];
Expand Down
12 changes: 12 additions & 0 deletions tests/Platforms/AbstractPlatformTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,18 @@ public function testEmptySchemaDiff(): void
self::assertSame([], $this->platform->getAlterSchemaSQL($diff));
}

public function testColumnComparison(): void
{
//Since DATETIME_MUTABLE is a "parent" of DATETIME_IMMUTABLE, they will have the same SQL type declaration.
$column1 = new Column('foo', Type::getType(Types::DATETIME_MUTABLE));
$column2 = new Column('foo', Type::getType(Types::DATETIME_IMMUTABLE));

self::assertFalse($this->platform->columnsEqual($column1, $column2));

$this->platform->setDisableTypeComments(true);
self::assertTrue($this->platform->columnsEqual($column1, $column2));
}

public function tearDown(): void
{
if (! isset($this->backedUpType)) {
Expand Down

0 comments on commit df1bd13

Please sign in to comment.