-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
gh-108364: In sqlite3, disable foreign keys before dumping SQL schema #108471
gh-108364: In sqlite3, disable foreign keys before dumping SQL schema #108471
Conversation
erlend-aasland
commented
Aug 25, 2023
•
edited by bedevere-bot
Loading
edited by bedevere-bot
- Issue: Align sqlite3.Connection.iterdump with the .dump() command of the SQLite shell #108364
I'm not sure who in the core team to call upon for a review of this. @felixxm, are you up for a review? 😃 |
@@ -26,6 +26,7 @@ def _iterdump(connection): | |||
|
|||
writeable_schema = False | |||
cu = connection.cursor() | |||
yield('PRAGMA foreign_keys=OFF;') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is consistent with the sqlite CLI .dump but seems to contradict the documentation here (section 2). Perhaps we should query foreign_keys
for future proofing?
Excerpt from section 2:
Foreign key constraints are disabled by default (for backwards compatibility), so must be enabled separately for each database connection. (Note, however, that future releases of SQLite might change so that foreign key constraints enabled by default. Careful developers will not make any assumptions about whether or not foreign keys are enabled by default but will instead enable or disable them as necessary.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can make assumptions about a connection on which the dump will be imported. We can check if there is any foreign key violation on the source database before adding this, e.g.
violations = cursor.execute("PRAGMA foreign_key_check").fetchall()
if len(violations) > 0:
yield('PRAGMA foreign_keys=OFF;')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@erlend-aasland Do you need help with this patch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@felixxm: I currently have very little bandwidth for CPython development. Feel free to take this over, if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in #113957.