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 <noreply@anthropic.com>
This commit is contained in:
parent
7e12f8c911
commit
db1d47ea94
3 changed files with 25 additions and 6 deletions
2
src-tauri/Cargo.lock
generated
2
src-tauri/Cargo.lock
generated
|
|
@ -3894,7 +3894,7 @@ checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "simpl-result"
|
name = "simpl-result"
|
||||||
version = "0.2.7"
|
version = "0.2.8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aes-gcm",
|
"aes-gcm",
|
||||||
"argon2",
|
"argon2",
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,25 @@ pub fn run() {
|
||||||
);",
|
);",
|
||||||
kind: MigrationKind::Up,
|
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()
|
tauri::Builder::default()
|
||||||
|
|
|
||||||
|
|
@ -31,15 +31,15 @@ export async function createImportedFile(file: {
|
||||||
notes?: string;
|
notes?: string;
|
||||||
}): Promise<number> {
|
}): Promise<number> {
|
||||||
const db = await getDb();
|
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<ImportedFile[]>(
|
const existing = await db.select<ImportedFile[]>(
|
||||||
"SELECT id FROM imported_files WHERE source_id = $1 AND file_hash = $2",
|
"SELECT id FROM imported_files WHERE source_id = $1 AND filename = $2",
|
||||||
[file.source_id, file.file_hash]
|
[file.source_id, file.filename]
|
||||||
);
|
);
|
||||||
if (existing.length > 0) {
|
if (existing.length > 0) {
|
||||||
await db.execute(
|
await db.execute(
|
||||||
`UPDATE imported_files SET filename = $1, row_count = $2, status = $3, notes = $4, import_date = CURRENT_TIMESTAMP WHERE id = $5`,
|
`UPDATE imported_files SET file_hash = $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]
|
[file.file_hash, file.row_count, file.status, file.notes || null, existing[0].id]
|
||||||
);
|
);
|
||||||
return existing[0].id;
|
return existing[0].id;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue