You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When `PostgreSQL.prototype.getDropForeignKeys` gets called with
duplicated foreign keys, an invalid `ALTER TABLE` statement gets
created. This is because the duplicates are mapped to multiple `DROP
CONSTRAINT fk_key` SQL actions, e.g.:
```sql
-- This will throw an error
ALTER TABLE "public"."foo"
DROP CONSTRAINT "fk_duplicatedKey",
DROP CONSTRAINT "fk_duplicatedKey",
DROP CONSTRAINT "fk_duplicatedKey",
DROP CONSTRAINT "fk_otherKey"
```
As the `DROP CONSTRAINT` actions are run sequentially, when the first
action gets executed by PostgreSQL, the next one (for the same, but
already dropped key) will not cause an SQL error thanks to the added IF
EXISTS check:
```sql
-- This is valid SQL
ALTER TABLE "public"."foo"
DROP CONSTRAINT IF EXISTS "fk_duplicatedKey",
DROP CONSTRAINT IF EXISTS "fk_duplicatedKey",
DROP CONSTRAINT IF EXISTS "fk_duplicatedKey",
DROP CONSTRAINT IF EXISTS "fk_otherKey"
```
Please note, this is really a hack and we still need to understand why
the method in question gets called with duplicated foreign keys in
certain conditions.
Signed-off-by: Chris Kobrzak <[email protected]>
Signed-off-by: SAMI BETTAYEB <[email protected]>
0 commit comments