From 57c98dadc96f13683f611f9138afec4282b6b784 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 | 14 +++++++++++--- 2 files changed, 15 insertions(+), 3 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 0c89f7541ab..656dec9c252 100644 --- a/tests/Schema/AbstractComparatorTestCase.php +++ b/tests/Schema/AbstractComparatorTestCase.php @@ -682,9 +682,17 @@ public function testDetectForeignKeyNameChange(): void $tableB->addColumn('ID', Types::INTEGER); $tableB->addForeignKeyConstraint('bar', ['id'], ['id'], [], 'bar_constraint'); - $tableDiff = $this->comparator->diffTable($tableA, $tableB); - - self::assertFalse($tableDiff); + $fkA = new ForeignKeyConstraint(['id'], 'bar', ['id'], 'foo_constraint'); + $fkA->setLocalTable($tableA); + $fkB = new ForeignKeyConstraint(['id'], 'bar', ['id'], 'bar_constraint'); + $fkB->setLocalTable($tableB); + $tableDiff = new TableDiff( + tableName: 'foo', + fromTable: $tableA, + addedForeignKeys: [$fkB], + removedForeignKeys: [$fkA], + ); + self::assertEquals($tableDiff, $this->comparator->compareTables($tableA, $tableB)); } public function testCompareForeignKeyRestrictNoActionAreTheSame(): void