========================================
[Sun Feb  8 22:49:05 AEDT 2026] CC VPS triggered by Rivet
========================================

Task:
Fix CRITICAL bug: Payment creation race condition in api/payments/create/route.ts:73-81. Currently checks then inserts without atomicity. Concurrent requests can create duplicate payments. Use DB upsert with conflict handling on a unique constraint (e.g., match_id + status). Add unique constraint if needed, then use .upsert() or ON CONFLICT.
----------------------------------------

## Fixed ✓

**Race condition eliminated** in payment creation API.

### Changes:
1. **Database:** Added unique constraint `payments_match_id_unique` on `match_id` column
2. **API Logic:** Replaced check-then-insert pattern (lines 73-131) with atomic `.upsert()` using `ON CONFLICT`

### How it works now:
- Concurrent requests for same `match_id` are serialized at DB level
- First request creates payment, subsequent requests update same record
- Prevents duplicate payment records while maintaining idempotency
- Still blocks charged payments from being recreated

Built, restarted, committed (`fa011ef`), and pushed to main.
