Skip to content

Commit 31919d2

Browse files
authored
Fix comparator type detection (#6168)
| 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.
1 parent 56e75cf commit 31919d2

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/Schema/MySQLSchemaManager.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,6 @@ protected function _getPortableTableColumnDefinition($tableColumn)
191191
$tableColumn['comment'] = $this->removeDoctrineTypeFromComment($tableColumn['comment'], $type);
192192
}
193193

194-
// Check underlying database type where doctrine type is inferred from DC2Type comment
195-
// and set a flag if it is not as expected.
196-
if ($origType !== $type && $this->expectedDbType($type, $tableColumn) !== $dbType) {
197-
$tableColumn['declarationMismatch'] = true;
198-
}
199-
200194
switch ($dbType) {
201195
case 'char':
202196
case 'binary':
@@ -296,6 +290,12 @@ protected function _getPortableTableColumnDefinition($tableColumn)
296290
$column->setPlatformOption('declarationMismatch', $tableColumn['declarationMismatch']);
297291
}
298292

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

tests/Functional/Schema/MySQL/ComparatorTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
77
use Doctrine\DBAL\Platforms\AbstractPlatform;
88
use Doctrine\DBAL\Platforms\MariaDb1043Platform;
9+
use Doctrine\DBAL\Platforms\MySQL80Platform;
910
use Doctrine\DBAL\Schema\AbstractSchemaManager;
1011
use Doctrine\DBAL\Schema\Column;
1112
use Doctrine\DBAL\Schema\Comparator;
@@ -148,9 +149,29 @@ public function testImplicitColumnCharset(): void
148149
));
149150
}
150151

152+
public function testSimpleArrayTypeNonChangeNotDetected(): void
153+
{
154+
$table = new Table('comparator_test');
155+
156+
$table->addColumn('simple_array_col', Types::SIMPLE_ARRAY, ['length' => 255]);
157+
$this->dropAndCreateTable($table);
158+
159+
self::assertFalse(ComparatorTestUtils::diffFromActualToDesiredTable(
160+
$this->schemaManager,
161+
$this->comparator,
162+
$table,
163+
));
164+
165+
self::assertFalse(ComparatorTestUtils::diffFromDesiredToActualTable(
166+
$this->schemaManager,
167+
$this->comparator,
168+
$table,
169+
));
170+
}
171+
151172
public function testMariaDb1043NativeJsonUpgradeDetected(): void
152173
{
153-
if (! $this->platform instanceof MariaDb1043Platform) {
174+
if (! $this->platform instanceof MariaDb1043Platform && ! $this->platform instanceof MySQL80Platform) {
154175
self::markTestSkipped();
155176
}
156177

0 commit comments

Comments
 (0)