Skip to content

Commit c01a43f

Browse files
committed
Fix SQLite FK handling in altered tables
SQLitePlatform::getForeignKeysInAlteredTable was broken due to getForeignKeys no longer returning constraint names as array keys. This change introduces a $keysByName map to track constraints with names, allowing dropped foreign keys to be properly matched and removed from the result set.
1 parent 6ffd603 commit c01a43f

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/Platforms/SQLitePlatform.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,23 @@ private function getForeignKeysInAlteredTable(TableDiff $diff): array
861861
{
862862
$oldTable = $diff->getOldTable();
863863
$foreignKeys = $oldTable->getForeignKeys();
864-
$nameMap = $this->getDiffColumnNameMap($diff);
864+
$keysByName = [];
865+
foreach ($foreignKeys as $key => $foreignKey) {
866+
$constraintName = $foreignKey->getObjectName();
867+
868+
if ($constraintName === null) {
869+
continue;
870+
}
871+
872+
$constraintKey = strtolower(
873+
$constraintName->getIdentifier()
874+
->getValue(),
875+
);
876+
877+
$keysByName[$constraintKey] = $key;
878+
}
879+
880+
$nameMap = $this->getDiffColumnNameMap($diff);
865881

866882
foreach ($foreignKeys as $key => $constraint) {
867883
$changed = false;
@@ -905,7 +921,7 @@ private function getForeignKeysInAlteredTable(TableDiff $diff): array
905921
->getValue(),
906922
);
907923

908-
unset($foreignKeys[$constraintKey]);
924+
unset($foreignKeys[$keysByName[$constraintKey]]);
909925
}
910926

911927
foreach ($diff->getAddedForeignKeys() as $constraint) {
@@ -917,7 +933,11 @@ private function getForeignKeysInAlteredTable(TableDiff $diff): array
917933
->getValue(),
918934
);
919935

920-
$foreignKeys[$constraintKey] = $constraint;
936+
if (isset($keysByName[$constraintKey])) {
937+
$foreignKeys[$keysByName[$constraintKey]] = $constraint;
938+
} else {
939+
$foreignKeys[] = $constraint;
940+
}
921941
} else {
922942
$foreignKeys[] = $constraint;
923943
}

0 commit comments

Comments
 (0)