01 · Before and afterThe pattern
// before: decided on an earlier read, executed unconditionally
await db.delete(items).where(eq(items.id, id));
// after: the condition travels with the write
const [gone] = await db.delete(items)
.where(and(eq(items.id, id), eq(items.isDeleted, true)))
.returning();
if (!gone) return; // restored meanwhile: keep it02 · Run it on your appThe check
If your job queue delivers the same message twice, does the job run twice?
If the honest answer is no or not sure, this is worth a look before it reaches production.