Skip to content

Commit

Permalink
Fix comparator type detection (#6168)
Browse files Browse the repository at this point in the history
|      Q       |   A
|------------- | -----------
| Type         | bug
| Fixed issues | contao/contao#6409

#### Summary

Since #5916 some column
configurations always show up as changed in the Comparator. For example
a `Types::SIMPLE_ARRAY, ['length' => 255]` column.

This pull request moves the `->expectedDbType()` check to the correct
position to fix this issue
and adds a test that verifies the fix.
  • Loading branch information
ausi authored Sep 29, 2023
1 parent 56e75cf commit 31919d2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/Schema/MySQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,6 @@ protected function _getPortableTableColumnDefinition($tableColumn)
$tableColumn['comment'] = $this->removeDoctrineTypeFromComment($tableColumn['comment'], $type);
}

// Check underlying database type where doctrine type is inferred from DC2Type comment
// and set a flag if it is not as expected.
if ($origType !== $type && $this->expectedDbType($type, $tableColumn) !== $dbType) {
$tableColumn['declarationMismatch'] = true;
}

switch ($dbType) {
case 'char':
case 'binary':
Expand Down Expand Up @@ -296,6 +290,12 @@ protected function _getPortableTableColumnDefinition($tableColumn)
$column->setPlatformOption('declarationMismatch', $tableColumn['declarationMismatch']);
}

// Check underlying database type where doctrine type is inferred from DC2Type comment
// and set a flag if it is not as expected.
if ($origType !== $type && $this->expectedDbType($type, $options) !== $dbType) {
$column->setPlatformOption('declarationMismatch', true);
}

return $column;
}

Expand Down
23 changes: 22 additions & 1 deletion tests/Functional/Schema/MySQL/ComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MariaDb1043Platform;
use Doctrine\DBAL\Platforms\MySQL80Platform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\Comparator;
Expand Down Expand Up @@ -148,9 +149,29 @@ public function testImplicitColumnCharset(): void
));
}

public function testSimpleArrayTypeNonChangeNotDetected(): void
{
$table = new Table('comparator_test');

$table->addColumn('simple_array_col', Types::SIMPLE_ARRAY, ['length' => 255]);
$this->dropAndCreateTable($table);

self::assertFalse(ComparatorTestUtils::diffFromActualToDesiredTable(
$this->schemaManager,
$this->comparator,
$table,
));

self::assertFalse(ComparatorTestUtils::diffFromDesiredToActualTable(
$this->schemaManager,
$this->comparator,
$table,
));
}

public function testMariaDb1043NativeJsonUpgradeDetected(): void
{
if (! $this->platform instanceof MariaDb1043Platform) {
if (! $this->platform instanceof MariaDb1043Platform && ! $this->platform instanceof MySQL80Platform) {
self::markTestSkipped();
}

Expand Down

0 comments on commit 31919d2

Please sign in to comment.