Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
f-jacobi opened this issue Dec 6, 2024 · 0 comments
Open

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

f-jacobi opened this issue Dec 6, 2024 · 0 comments
Assignees
Labels

Comments

@f-jacobi
Copy link

f-jacobi commented Dec 6, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 📌 To do
Development

No branches or pull requests

2 participants