Skip to content

Support disabling of Foreign Key Constraint in exported SQL dump #903

Open
@f-jacobi

Description

@f-jacobi

Is your feature request related to a problem? Please describe.
Supposed I have a database dump (content only) that was created via Antares, e.g. for a PostgreSQL database.
When I try to import this dump into an empty database, I may get foreign key constraint violations, when there are INSERT statements that refer to primary IDs that are INSERTed later.
One reason is that Antares exports the tables in alphabetical order, not in order of dependency.

Describe the solution you'd like
The dump should contain statements that disable foreign key constraints at the beginning, and enable the constraints again at the end.
I see two ways for PostgreSQL but are not sure if this would be the best way.

  1. Enter replica mode: SET session_replication_role = replica; and afterwards SET session_replication_role = DEFAULT;. See https://stackoverflow.com/questions/3942258/how-do-i-temporarily-disable-triggers-in-postgresql or https://postgresqlco.nf/doc/en/param/session_replication_role/.
  2. Disable triggers for each table: ALTER TABLE tab_name DISABLE TRIGGER ALL; and afterwards ALTER TABLE tab_name ENABE TRIGGER ALL;. See also https://stackoverflow.com/questions/3942258/how-do-i-temporarily-disable-triggers-in-postgresql or https://www.commandprompt.com/education/how-to-disable-a-trigger-in-postgresql/.

Describe alternatives you've considered
An alternative would be sorting the tables in the dump in order of dependency, but this seems quite hard.

Additional context
Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

📌 To do

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions