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 <christoph.krapp@power.cloud>
  • Loading branch information
Christoph Krapp committed Jun 2, 2024
1 parent 7ad0ff8 commit 3dd6269
Show file tree
Hide file tree
Showing 2 changed files with 12 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 @@ -371,6 +371,10 @@ private function detectRenamedIndexes(array &$addedIndexes, array &$removedIndex

protected function diffForeignKey(ForeignKeyConstraint $key1, ForeignKeyConstraint $key2): bool
{
if (strtolower($key1->getName()) !== strtolower($key2->getName())) {
return true;
}

if (
array_map('strtolower', $key1->getUnquotedLocalColumns())
!== array_map('strtolower', $key2->getUnquotedLocalColumns())
Expand Down
11 changes: 8 additions & 3 deletions tests/Schema/AbstractComparatorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,14 @@ public function testCompareForeignKeyBasedOnPropertiesNotName(): void
$tableB->addColumn('ID', Types::INTEGER);
$tableB->addForeignKeyConstraint('bar', ['id'], ['id'], [], 'bar_constraint');

$tableDiff = $this->comparator->compareTables($tableA, $tableB);

self::assertTrue($tableDiff->isEmpty());
self::assertEquals(
new TableDiff($tableA, [], [], [], [], [], [], [], [], [
new ForeignKeyConstraint(['id'], 'bar', ['id'], 'bar_constraint'),
], [], [
new ForeignKeyConstraint(['id'], 'bar', ['id'], 'foo_constraint'),
]),
$this->comparator->compareTables($tableA, $tableB),
);
}

public function testDetectRenameColumn(): void
Expand Down

0 comments on commit 3dd6269

Please sign in to comment.