Persist versioned document text reviews against source file hashes

This commit is contained in:
2026-09-06 09:47:12 +03:00
parent f073438922
commit 559a2feeda
7 changed files with 120 additions and 2 deletions
+17 -1
View File
@@ -65,6 +65,13 @@ CREATE TABLE IF NOT EXISTS api_anahtarlari (
CREATE INDEX IF NOT EXISTS idx_apikey_hash ON api_anahtarlari(hash);
CREATE INDEX IF NOT EXISTS idx_apikey_email ON api_anahtarlari(email);
CREATE TABLE IF NOT EXISTS document_text_reviews (
document_id TEXT NOT NULL, email TEXT NOT NULL, revision INTEGER NOT NULL,
file_hash TEXT NOT NULL, text_hash TEXT NOT NULL, corrected_text TEXT NOT NULL,
review_note TEXT NOT NULL, reviewed_at TEXT NOT NULL,
PRIMARY KEY (document_id,email,revision)
);
CREATE TABLE IF NOT EXISTS belgeler (
id TEXT PRIMARY KEY,
email TEXT NOT NULL,
@@ -107,6 +114,8 @@ export function openDb() {
.run('20260906_document_type', new Date().toISOString());
db.prepare('INSERT OR IGNORE INTO schema_migrations VALUES (?,?)')
.run('20260906_document_processing', new Date().toISOString());
db.prepare('INSERT OR IGNORE INTO schema_migrations VALUES (?,?)')
.run('20260906_document_text_reviews', new Date().toISOString());
db.exec('COMMIT');
} catch (error) {
try { db.exec('ROLLBACK'); } catch { /* original error is authoritative */ }
@@ -315,7 +324,14 @@ export function deleteDocument(email, id) {
if (!rec) return false;
try { fs.unlinkSync(path.join(BELGE_DIR, rec.dosya)); }
catch (error) { if (error.code !== 'ENOENT') throw error; }
return withDb((db) => db.prepare('DELETE FROM belgeler WHERE id=? AND email=?').run(id, email).changes > 0, false);
return withDb((db) => {
db.exec('BEGIN IMMEDIATE');
try {
db.prepare('DELETE FROM document_text_reviews WHERE document_id=? AND email=?').run(id,email);
const changed=db.prepare('DELETE FROM belgeler WHERE id=? AND email=?').run(id,email).changes>0;
db.exec('COMMIT');return changed;
} catch(error) {db.exec('ROLLBACK');throw error;}
});
}
export function documentUsage(email) {