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

db: defer sqlite foreign keys during migration #454

Merged

Conversation

sgotti
Copy link
Member

@sgotti sgotti commented Nov 13, 2023

Sqlite provides only limited alter tables capabilities, complex things must be done by creating a new table and migrating the data. Things becomes more complex when other tables references the table being altered.

For doing this the documentation provides a list of steps https://www.sqlite.org/lang_altertable.html#making_other_kinds_of_table_schema_changes The first stable is disabling foreign keys, but this must be done outside a transaction.

This patch adds this to the migration logic: disable foreign keys outside transaction, check foreign keys before committing the transaction and then re enable them outside the transaction.

Sqlite provides only limited alter tables capabilities, complex things
must be done by creating a new table and migrating the data. Things
becomes more complex when other tables references the table being
altered.

For doing this the documentation provides a list of steps
https://www.sqlite.org/lang_altertable.html#making_other_kinds_of_table_schema_changes
The first stable is disabling foreign keys, but this must be done
outside a transaction.

This patch adds this to the migration logic: disable foreign keys
outside transaction, check foreign keys before committing the
transaction and then re enable them outside the transaction.
@sgotti sgotti merged commit 6c4d0b1 into agola-io:master Nov 13, 2023
1 check was pending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant