Project
vgrep
Description
SQLite foreign keys are disabled by default. The schema in src/core/db.rs defines FOREIGN KEY (file_id) REFERENCES files(id) ON DELETE CASCADE but the code never executes PRAGMA foreign_keys = ON;. This means the cascade delete constraint is ignored, leaving orphaned chunks in the database when files are deleted.
Error Message
N/A - Silent data corruption. No error is raised; orphan data simply accumulates.
Debug Logs
N/A - This bug does not produce log output. Can be verified by querying:
sqlite3 ~/.vgrep/projects/*.db "SELECT COUNT(*) FROM chunks WHERE file_id NOT IN (SELECT id FROM files);"
System Information
vgrep version: 0.1.0
Rust: stable (as per rust-toolchain.toml)
SQLite: bundled via rusqlite 0.32
Screenshots
No response
Steps to Reproduce
- Run
vgrep index on a directory containing source files
- Open the SQLite database directly:
sqlite3 ~/.vgrep/projects/<hash>.db
- Execute:
DELETE FROM files WHERE id = 1;
- Query orphaned chunks:
SELECT COUNT(*) FROM chunks WHERE file_id = 1;
- Observe that chunks still exist despite their parent file being deleted
Expected Behavior
When a file row is deleted from the files table, all associated chunks in the chunks table should be automatically deleted via the ON DELETE CASCADE foreign key constraint.
Actual Behavior
Chunks with file_id referencing deleted files remain in the database indefinitely. SQLite silently ignores the foreign key constraint because PRAGMA foreign_keys defaults to OFF.
Additional Context
File: src/core/db.rs
Function: init_schema() (lines 55-83)
Fix direction: Add PRAGMA foreign_keys = ON; as the first statement in init_schema().
Project
vgrep
Description
SQLite foreign keys are disabled by default. The schema in
src/core/db.rsdefinesFOREIGN KEY (file_id) REFERENCES files(id) ON DELETE CASCADEbut the code never executesPRAGMA foreign_keys = ON;. This means the cascade delete constraint is ignored, leaving orphaned chunks in the database when files are deleted.Error Message
N/A - Silent data corruption. No error is raised; orphan data simply accumulates.Debug Logs
System Information
Screenshots
No response
Steps to Reproduce
vgrep indexon a directory containing source filessqlite3 ~/.vgrep/projects/<hash>.dbDELETE FROM files WHERE id = 1;SELECT COUNT(*) FROM chunks WHERE file_id = 1;Expected Behavior
When a file row is deleted from the
filestable, all associated chunks in thechunkstable should be automatically deleted via theON DELETE CASCADEforeign key constraint.Actual Behavior
Chunks with
file_idreferencing deleted files remain in the database indefinitely. SQLite silently ignores the foreign key constraint becausePRAGMA foreign_keysdefaults toOFF.Additional Context
File:
src/core/db.rsFunction:
init_schema()(lines 55-83)Fix direction: Add
PRAGMA foreign_keys = ON;as the first statement ininit_schema().