Repository navigation
fix(core): correct documents_fts update/delete triggers for external-content FTS5 - #1351
Merged
Merged
Conversation
…content FTS5 documents_fts is an external-content FTS5 table, so the update and delete triggers must issue the 'delete' command with the OLD values. The plain UPDATE/DELETE forms either failed with 'database disk image is malformed' (title changes via doc update/upsert) or silently left stale tokens in the index. Replace the triggers (new databases and the v12 migration) and heal existing databases on open: swap the outdated triggers and rebuild the index. Fixes #1349 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
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
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.
What
documents_fts_updateanddocuments_fts_deletenow use the FTS5'delete'command with the OLD row values (asmemories_ftsalready does). Defined once as constants and used byensure_documents_fts_createand the v12 migration list.heal_documents_fts_triggers()runs when an existingdocuments_ftsis found on open: if either trigger is the old plainUPDATE/DELETEform it drops and recreates it and runsINSERT INTO documents_fts(documents_fts) VALUES('rebuild')so stale tokens disappear. Idempotent (no-op once correct); no schema version bump.Why
documents_ftsis an external-content FTS5 table (content='documents'). A plainUPDATE documents_fts SET …/DELETE FROM documents_fts …makes FTS5 re-read the already-modified content row, which either aborts withdatabase disk image is malformed(reported as "update document: database corruption") or silently leaves the old title/content tokens in the index. Found while writing the #1341 tests; see #1349.Testing
update_document+upsert_documentkeeps FTS in sync (old title no longer matches, new one does);doc_update/doc_upserttitle changes work throughUtekewith an embedder;heal_documents_fts_triggers()fixes it and removes stale entries, second call is a no-op;cargo fmt --check,cargo clippy --workspace --all-targetsclean;cargo test --workspacegreen (core 603); vecq-only core build green (601).rebuildis a one-time cost on first open after upgrade).Fixes #1349
🤖 Generated with Claude Code