Opus finding
`outgoingPrs.mergeSha` lacks a CHECK or NOT NULL constraint despite the receipts loader treating it as required
lowdata-losshigh
- apps/web/db/schema.ts:175-195
- apps/web/lib/receipts.ts:100-130
The schema allows a row to be `status='merged'` while mergeSha or mergedAt is null. mapMergedRowsToReceipts defensively skips such rows, but they would silently disappear from /receipts without any operator-visible warning. A CHECK constraint pinning (status='merged' implies mergeSha IS NOT NULL AND mergedAt IS NOT NULL) would surface bad writes at insert time. The author acknowledges this in a code comment ('the table has no CHECK constraint pinning that invariant').
Recommendation
Add a CHECK constraint: `CHECK ((status <> 'merged') OR (merge_sha IS NOT NULL AND merged_at IS NOT NULL))`.