From db1d47ea94c40ac56b7e4a3a9cb9734d95af425f Mon Sep 17 00:00:00 2001 From: Le-King-Fu Date: Sun, 15 Feb 2026 12:40:01 +0000 Subject: [PATCH] fix: allow duplicate-content files with different names (#1) Change imported_files UNIQUE constraint from (source_id, file_hash) to (source_id, filename) so files with identical content but different names each get their own record. Update createImportedFile to look up existing records by filename instead of hash. Co-Authored-By: Claude Opus 4.6 --- src-tauri/Cargo.lock | 2 +- src-tauri/src/lib.rs | 19 +++++++++++++++++++ src/services/importedFileService.ts | 10 +++++----- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 0839086..48113b8 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -3894,7 +3894,7 @@ checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2" [[package]] name = "simpl-result" -version = "0.2.7" +version = "0.2.8" dependencies = [ "aes-gcm", "argon2", diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index ee9b790..38b158f 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -48,6 +48,25 @@ pub fn run() { );", kind: MigrationKind::Up, }, + Migration { + version: 6, + description: "change imported_files unique constraint from hash to filename", + sql: "CREATE TABLE imported_files_new ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + source_id INTEGER NOT NULL REFERENCES import_sources(id), + filename TEXT NOT NULL, + file_hash TEXT NOT NULL, + import_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + row_count INTEGER NOT NULL DEFAULT 0, + status TEXT NOT NULL DEFAULT 'completed', + notes TEXT, + UNIQUE(source_id, filename) + ); + INSERT INTO imported_files_new SELECT * FROM imported_files; + DROP TABLE imported_files; + ALTER TABLE imported_files_new RENAME TO imported_files;", + kind: MigrationKind::Up, + }, ]; tauri::Builder::default() diff --git a/src/services/importedFileService.ts b/src/services/importedFileService.ts index cf02ccf..bb2c9df 100644 --- a/src/services/importedFileService.ts +++ b/src/services/importedFileService.ts @@ -31,15 +31,15 @@ export async function createImportedFile(file: { notes?: string; }): Promise { const db = await getDb(); - // Check if file already exists (e.g. from a previous failed import) + // Check if file already exists by filename (e.g. re-import of same file) const existing = await db.select( - "SELECT id FROM imported_files WHERE source_id = $1 AND file_hash = $2", - [file.source_id, file.file_hash] + "SELECT id FROM imported_files WHERE source_id = $1 AND filename = $2", + [file.source_id, file.filename] ); if (existing.length > 0) { await db.execute( - `UPDATE imported_files SET filename = $1, row_count = $2, status = $3, notes = $4, import_date = CURRENT_TIMESTAMP WHERE id = $5`, - [file.filename, file.row_count, file.status, file.notes || null, existing[0].id] + `UPDATE imported_files SET file_hash = $1, row_count = $2, status = $3, notes = $4, import_date = CURRENT_TIMESTAMP WHERE id = $5`, + [file.file_hash, file.row_count, file.status, file.notes || null, existing[0].id] ); return existing[0].id; }