fix: SQLite foreign keys not enabled; CASCADE deletions silently fail #1172
+83
−5
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.
Summary
This PR fixes #1098
Changes
_foreign_keys=1pragma to SQLite connection inpkg/memory/database/sqlite/sqlite.go_pragma=foreign_keys(1)to SQLite connections in:pkg/rag/strategy/bm25_database.gopkg/rag/strategy/chunked_embeddings_database.gopkg/rag/strategy/semantic_embeddings_database.go_foreign_keys=1pragma to SQLite connection inpkg/session/store.goWhy
SQLite does not enforce foreign key constraints by default. Without explicitly enabling them via
PRAGMA foreign_keys = ON,ON DELETE CASCADEconstraints are silently ignored, leading to orphan records in the database.Testing
TestChunkedVectorDB_ForeignKeyCascadeDelete- verifies CASCADE deletion worksTestChunkedVectorDB_ForeignKeyConstraintEnforced- verifies constraint violations are rejected