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
achterin authored and uncaught committed Sep 6, 2024
1 parent 67305ee commit 57c98da
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 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
14 changes: 11 additions & 3 deletions tests/Schema/AbstractComparatorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 57c98da

Please sign in to comment.