Skip to content

Commit

Permalink
Merge pull request #6413 from achterin/bugfix/foreign_key_name_change…
Browse files Browse the repository at this point in the history
…_detection

Fix foreign key name change detection
  • Loading branch information
greg0ire authored Jun 1, 2024
2 parents a5d2baf + 422e459 commit 080aab5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 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
9 changes: 5 additions & 4 deletions tests/Schema/AbstractComparatorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ public function testCompareColumnCompareCaseInsensitive(): void
self::assertFalse($tableDiff);
}

public function testCompareIndexBasedOnPropertiesNotName(): void
public function testDetectIndexNameChange(): void
{
$tableA = new Table('foo');
$tableA->addColumn('id', Types::INTEGER);
Expand All @@ -672,7 +672,7 @@ public function testCompareIndexBasedOnPropertiesNotName(): void
);
}

public function testCompareForeignKeyBasedOnPropertiesNotName(): void
public function testDetectForeignKeyNameChange(): void
{
$tableA = new Table('foo');
$tableA->addColumn('id', Types::INTEGER);
Expand All @@ -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 080aab5

Please sign in to comment.