From 3dd626943a7a99ccdb682bc733845f19aae9b765 Mon Sep 17 00:00:00 2001 From: Christoph Krapp Date: Tue, 28 May 2024 23:39:47 +0200 Subject: [PATCH] Fix fk name change detection in schema comparator As index renaming support was introduced a while back do the same for foreign key name changes. Signed-off-by: Christoph Krapp --- src/Schema/Comparator.php | 4 ++++ tests/Schema/AbstractComparatorTestCase.php | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Schema/Comparator.php b/src/Schema/Comparator.php index 4c60c0770a3..d349af07fcf 100644 --- a/src/Schema/Comparator.php +++ b/src/Schema/Comparator.php @@ -371,6 +371,10 @@ private function detectRenamedIndexes(array &$addedIndexes, array &$removedIndex protected function diffForeignKey(ForeignKeyConstraint $key1, ForeignKeyConstraint $key2): bool { + if (strtolower($key1->getName()) !== strtolower($key2->getName())) { + return true; + } + if ( array_map('strtolower', $key1->getUnquotedLocalColumns()) !== array_map('strtolower', $key2->getUnquotedLocalColumns()) diff --git a/tests/Schema/AbstractComparatorTestCase.php b/tests/Schema/AbstractComparatorTestCase.php index 4b9ec2c2af6..ee64a1584ff 100644 --- a/tests/Schema/AbstractComparatorTestCase.php +++ b/tests/Schema/AbstractComparatorTestCase.php @@ -373,9 +373,14 @@ public function testCompareForeignKeyBasedOnPropertiesNotName(): void $tableB->addColumn('ID', Types::INTEGER); $tableB->addForeignKeyConstraint('bar', ['id'], ['id'], [], 'bar_constraint'); - $tableDiff = $this->comparator->compareTables($tableA, $tableB); - - self::assertTrue($tableDiff->isEmpty()); + self::assertEquals( + new TableDiff($tableA, [], [], [], [], [], [], [], [], [ + new ForeignKeyConstraint(['id'], 'bar', ['id'], 'bar_constraint'), + ], [], [ + new ForeignKeyConstraint(['id'], 'bar', ['id'], 'foo_constraint'), + ]), + $this->comparator->compareTables($tableA, $tableB), + ); } public function testDetectRenameColumn(): void