01 · Before and afterThe pattern
// before: check, then write by id
if (isMutable(c.payment?.status)) await db.credit.updateMany({ where: { id: { in: ids } }, data });
// after: the check is part of the write
await db.credit.updateMany({
where: { id: { in: ids }, OR: [{ paymentId: null }, { payment: { status: { in: MUTABLE } } }] },
data,
});02 · Run it on your appThe check
When you move or edit money records, is the “still editable” condition inside the UPDATE statement, not just in an earlier read?
If the honest answer is no or not sure, this is worth a look before it reaches production.