From 0aa672aa69f0bccea3ed0b7854305130a222d00e 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 | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Schema/Comparator.php b/src/Schema/Comparator.php index 28e7f2f73b2..804c981702b 100644 --- a/src/Schema/Comparator.php +++ b/src/Schema/Comparator.php @@ -555,6 +555,10 @@ private function detectRenamedIndexes(array &$addedIndexes, array &$removedIndex */ public function diffForeignKey(ForeignKeyConstraint $key1, ForeignKeyConstraint $key2) { + 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 a087202628f..6c222f21cef 100644 --- a/tests/Schema/AbstractComparatorTestCase.php +++ b/tests/Schema/AbstractComparatorTestCase.php @@ -683,8 +683,9 @@ public function testCompareForeignKeyBasedOnPropertiesNotName(): void $tableB->addForeignKeyConstraint('bar', ['id'], ['id'], [], 'bar_constraint'); $tableDiff = $this->comparator->diffTable($tableA, $tableB); - - self::assertFalse($tableDiff); + self::assertNotFalse($tableDiff); + self::assertCount(1, $tableDiff->addedForeignKeys); + self::assertCount(1, $tableDiff->removedForeignKeys); } public function testCompareForeignKeyRestrictNoActionAreTheSame(): void