mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-08-23 23:02:17 +10:00
fix(resume): guard patch versions in the transaction, not in sql
Postgres defaultNow() stores microseconds while JS Dates are millisecond-truncated, so the SQL equality guard matched zero rows on freshly created resumes and every guarded agent patch failed with a permanent version conflict. The SELECT ... FOR UPDATE lock plus the in-transaction ms-precision check already provide the guarantee; drop the SQL predicate. Verified A/B against a live database.
This commit is contained in:
@@ -160,16 +160,15 @@ async function applyResumePatchTx(
|
|||||||
}
|
}
|
||||||
|
|
||||||
patchedData = parseWritableResumeData(patchedData);
|
patchedData = parseWritableResumeData(patchedData);
|
||||||
|
// The version guard is the ms-precision JS check above, under the SELECT ... FOR UPDATE lock.
|
||||||
|
// Never compare expectedUpdatedAt in SQL: rows stamped by Postgres now() (defaultNow() on
|
||||||
|
// insert) carry microseconds, while JS Dates are ms-truncated — SQL equality then matches
|
||||||
|
// zero rows and every guarded patch on a fresh resume reports a version conflict forever.
|
||||||
const [resume] = await client
|
const [resume] = await client
|
||||||
.update(schema.resume)
|
.update(schema.resume)
|
||||||
.set({ data: patchedData })
|
.set({ data: patchedData })
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(eq(schema.resume.id, input.id), eq(schema.resume.isLocked, false), eq(schema.resume.userId, input.userId)),
|
||||||
eq(schema.resume.id, input.id),
|
|
||||||
eq(schema.resume.isLocked, false),
|
|
||||||
eq(schema.resume.userId, input.userId),
|
|
||||||
...(input.expectedUpdatedAt ? [eq(schema.resume.updatedAt, input.expectedUpdatedAt)] : []),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.returning({
|
.returning({
|
||||||
id: schema.resume.id,
|
id: schema.resume.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user