Skip to content

Commit

Permalink
Fix fk name change detection in schema comparator
Browse files Browse the repository at this point in the history
As index renaming support was introduced a while back do the same for
foreign key name changes.

Signed-off-by: Christoph Krapp <[email protected]>
  • Loading branch information
Christoph Krapp committed Jun 1, 2024
1 parent a5d2baf commit 0aa672a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/Schema/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
5 changes: 3 additions & 2 deletions tests/Schema/AbstractComparatorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0aa672a

Please sign in to comment.