Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix comparator type detection #6168

Merged
merged 1 commit into from
Sep 29, 2023
Merged
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
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