-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Labels
Description
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 --forceSystem Information
OS: Ubuntu 22.04
vgrep version: 0.1.0
SQLite: bundled via rusqlite 0.32Screenshots
No response
Steps to Reproduce
- Run
vgrep indexon 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