Commit 985bcee
committed
fix(db): add forwarder_sent.audit_log_id real UUID FK to audit_log (mig 072)
Companion to the soft-FK partial index from mig 063. Adds a proper nullable
UUID column + ON DELETE SET NULL FK so the orphan-reconciler and team-deletion
cascade can use a typed JOIN instead of regex-based TEXT comparison.
Why a separate column: forwarder_sent.audit_id is TEXT on purpose — legacy
emit sites write placeholder IDs like "reminder-<resource>-<stage>" that
cannot be parsed as UUIDs. A FK on the TEXT column would reject those rows
(see mig 063 for full rationale). This column is populated only when
audit_id IS a real UUID; placeholder-id rows keep NULL.
One-time backfill: UPDATE sets audit_log_id = audit_id::uuid for existing
rows whose audit_id is UUID-shaped AND whose id still exists in audit_log
(ON DELETE SET NULL already handles deletions). The mig-063 partial index
keeps the scan fast even at scale.
Wire-up required: the worker's event_email_forwarder must set audit_log_id
on new inserts (companion PR in worker repo).1 parent 30e1a88 commit 985bcee
1 file changed
Lines changed: 48 additions & 0 deletions
Lines changed: 48 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
0 commit comments