From 9a5cdad86ed73d1e2684e1a07cdaca2c52763fa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Thu, 16 Apr 2026 22:55:33 -0400 Subject: [PATCH] fix(db): use single timestamp in markRefreshed + recordAutomationExecution (P1-23, P3-46) --- src/main/database/automation.ts | 5 +++-- src/main/database/credentials.ts | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/database/automation.ts b/src/main/database/automation.ts index 50651af1..11b7fea9 100644 --- a/src/main/database/automation.ts +++ b/src/main/database/automation.ts @@ -53,8 +53,9 @@ export function buildAutomationMethods( recordAutomationExecution(ruleId: string, companyId: string, ruleName: string, trigger: string, action: string, detail: string) { const id = randomUUID(); - getDb().prepare("insert into automation_log (id, company_id, rule_id, rule_name, trigger, action, detail, executed_at) values (?, ?, ?, ?, ?, ?, ?, ?)").run(id, companyId, ruleId, ruleName, trigger, action, detail, nowIso()); - getDb().prepare("update automation_rules set execution_count = execution_count + 1, last_executed_at = ? where id = ?").run(nowIso(), ruleId); + const ts = nowIso(); + getDb().prepare("insert into automation_log (id, company_id, rule_id, rule_name, trigger, action, detail, executed_at) values (?, ?, ?, ?, ?, ?, ?, ?)").run(id, companyId, ruleId, ruleName, trigger, action, detail, ts); + getDb().prepare("update automation_rules set execution_count = execution_count + 1, last_executed_at = ? where id = ?").run(ts, ruleId); }, getAutomationLog(companyId: string) { diff --git a/src/main/database/credentials.ts b/src/main/database/credentials.ts index 3b960be0..6b4f52cf 100644 --- a/src/main/database/credentials.ts +++ b/src/main/database/credentials.ts @@ -166,11 +166,12 @@ export function buildCredentialMethods( ciphertext: Uint8Array, expiresAt: string | null, ): void { + const ts = nowIso(); getDb() .prepare( "update credentials set backend = ?, ciphertext = ?, expires_at = ?, last_refreshed_at = ?, status = 'active', last_error = null, updated_at = ? where connector_id = ?", ) - .run(backend, ciphertext, expiresAt, nowIso(), nowIso(), connectorId); + .run(backend, ciphertext, expiresAt, ts, ts, connectorId); } return { list, get, upsert, remove, setStatus, markRefreshed };