Skip to content

Commit 080aab5

Browse files
authored
Merge pull request #6413 from achterin/bugfix/foreign_key_name_change_detection
Fix foreign key name change detection
2 parents a5d2baf + 422e459 commit 080aab5

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/Schema/Comparator.php

+4
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,10 @@ private function detectRenamedIndexes(array &$addedIndexes, array &$removedIndex
555555
*/
556556
public function diffForeignKey(ForeignKeyConstraint $key1, ForeignKeyConstraint $key2)
557557
{
558+
if (strtolower($key1->getName()) !== strtolower($key2->getName())) {
559+
return true;
560+
}
561+
558562
if (
559563
array_map('strtolower', $key1->getUnquotedLocalColumns())
560564
!== array_map('strtolower', $key2->getUnquotedLocalColumns())

tests/Schema/AbstractComparatorTestCase.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ public function testCompareColumnCompareCaseInsensitive(): void
652652
self::assertFalse($tableDiff);
653653
}
654654

655-
public function testCompareIndexBasedOnPropertiesNotName(): void
655+
public function testDetectIndexNameChange(): void
656656
{
657657
$tableA = new Table('foo');
658658
$tableA->addColumn('id', Types::INTEGER);
@@ -672,7 +672,7 @@ public function testCompareIndexBasedOnPropertiesNotName(): void
672672
);
673673
}
674674

675-
public function testCompareForeignKeyBasedOnPropertiesNotName(): void
675+
public function testDetectForeignKeyNameChange(): void
676676
{
677677
$tableA = new Table('foo');
678678
$tableA->addColumn('id', Types::INTEGER);
@@ -683,8 +683,9 @@ public function testCompareForeignKeyBasedOnPropertiesNotName(): void
683683
$tableB->addForeignKeyConstraint('bar', ['id'], ['id'], [], 'bar_constraint');
684684

685685
$tableDiff = $this->comparator->diffTable($tableA, $tableB);
686-
687-
self::assertFalse($tableDiff);
686+
self::assertNotFalse($tableDiff);
687+
self::assertCount(1, $tableDiff->addedForeignKeys);
688+
self::assertCount(1, $tableDiff->removedForeignKeys);
688689
}
689690

690691
public function testCompareForeignKeyRestrictNoActionAreTheSame(): void

0 commit comments

Comments
 (0)