FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-108364: In sqlite3, disable foreign keys before dumping SQL schema by erlend-aasland · Pull Request #108471 · python/cpython · GitHub

Repository navigation

gh-108364: In sqlite3, disable foreign keys before dumping SQL schema - #108471

Closed
erlend-aasland wants to merge 6 commits into
python:mainfrom
erlend-aasland:sqlite/iterdump/foreign-keys
Closed

erlend-aasland wants to merge 6 commits into
python:mainfrom
erlend-aasland:sqlite/iterdump/foreign-keys

Conversation

erlend-aasland commented Aug 25, 2023 •
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown
Contributor Author

I'm not sure who in the core team to call upon for a review of this. @felixxm, are you up for a review? 😃

Comment thread Lib/sqlite3/dump.py

writeable_schema = False
cu = connection.cursor()
yield('PRAGMA foreign_keys=OFF;')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.)

felixxm Aug 31, 2023 •
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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;')

felixxm Sep 20, 2023 •
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@erlend-aasland Do you need help with this patch?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@felixxm: I currently have very little bandwidth for CPython development. Feel free to take this over, if you want.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Updated in #113957.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL