insert_guarded persisted the subscription-invoice prepaid draw-down by
writing rago_billing::prepaid::apply_prepaid_credit's precomputed absolute
Wallet balance (updated_wallets), which was read via wallets_for_customer
before the guarded transaction even began and under no row lock. A customer
can fund more than one subscription from the same wallet, and the durable
job queue (FOR UPDATE SKIP LOCKED) is built so multiple workers bill
different subscriptions concurrently — two such invoices could both read the
same stale balance, and whichever transaction committed last silently
clobbered the other's draw-down (a classic lost-update race), under-billing
the wallet relative to the sum of its own wallet_transactions rows.
Replace the absolute write with apply_prepaid_draw_down_exec: locks the
wallet row (SELECT ... FOR UPDATE) inside the same transaction, re-derives
the decrement in cents from the wallet_transaction's own amount against the
locked row's live currency, and applies it as a relative
balance_cents = balance_cents - decrement. A second concurrent caller now
blocks on the row lock and decrements from the already-updated value, so
both draw-downs land instead of one disappearing. Removes the now-dead
update_wallet_balance_exec helper this replaces.