(fix):db: pragma foreign keys to work with sqlite3 #2018
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit is follow-up for PR #2009 should fix issues #1927 & #1910.
Currently,
[:pragma (= foreign_keys ON)]
is present only in functionorg-roam-db--init
. This means theforeign_keys
is turned on only when the dbfile is created for the first time. Subsequent Emacs sessions won't turn it on
as the db file is already present and does not evaluate
org-roam-db--init
.This PRAGMA needs to be turned on each database connection at runtime according
to sqlite's documentation (https://sqlite.org/foreignkeys.html#fk_enable)
I have observed that on Windows only the Emacs session that initially creates
the Org-roam db file works correctly with the
sqlite3
option. Subsequent Emacssessions have the same "Unique constraint failed" error messages.
I have tested this patch on Windows and Ubuntu; both seem to work in the first
and subsequent Emacs sessions.
I am not 100% sure if the location of the PRAGMA is the best; use it as a
proof-of-cocenpt for the fix. Thank you.
Motivation for this change