Project
vgrep
Description
The insert_file() function uses INSERT OR REPLACE which, when updating an existing file, deletes the old row and creates a new one with a new auto-incremented ID. This changes the file's ID and can break the relationship with existing chunks if the deletion timing is off.
Error Message
N/A - Silent data integrity issue.
Debug Logs
# Can observe by checking file IDs before and after re-indexing:
sqlite3 ~/.vgrep/projects/*.db "SELECT id, path FROM files;"
# IDs change on each re-index with --force
System Information
OS: Ubuntu 22.04
vgrep version: 0.1.0
SQLite: bundled via rusqlite 0.32
Screenshots
No response
Steps to Reproduce
- Run
vgrep index on a directory
- Query file IDs:
sqlite3 ~/.vgrep/projects/*.db "SELECT id, path FROM files LIMIT 5;"
- Run
vgrep index --force
- Query file IDs again
- Observe that all file IDs have changed
Expected Behavior
File IDs should remain stable for the same path to maintain referential integrity. Updates should modify the existing row rather than delete and recreate.
Actual Behavior
INSERT OR REPLACE deletes the existing row and inserts a new one with a new auto-incremented ID.
Additional Context
File: src/core/db.rs
Function: insert_file() (lines 107-117)
Problematic code:
self.conn.execute(
"INSERT OR REPLACE INTO files (path, hash, indexed_at) VALUES (?, ?, ?)",
params![path_str.as_ref(), hash, now],
)?;
Ok(self.conn.last_insert_rowid()) // Returns new ID, not original
Project
vgrep
Description
The
insert_file()function usesINSERT OR REPLACEwhich, when updating an existing file, deletes the old row and creates a new one with a new auto-incremented ID. This changes the file's ID and can break the relationship with existing chunks if the deletion timing is off.Error Message
Debug Logs
System Information
Screenshots
No response
Steps to Reproduce
vgrep indexon a directorysqlite3 ~/.vgrep/projects/*.db "SELECT id, path FROM files LIMIT 5;"vgrep index --forceExpected Behavior
File IDs should remain stable for the same path to maintain referential integrity. Updates should modify the existing row rather than delete and recreate.
Actual Behavior
INSERT OR REPLACEdeletes the existing row and inserts a new one with a new auto-incremented ID.Additional Context
File:
src/core/db.rsFunction:
insert_file()(lines 107-117)Problematic code: