Skip to content

fix(worker): populate forwarder_sent.audit_log_id for UUID-shaped audit_ids#108

Merged
mastermanas805 merged 4 commits into
masterfrom
fix/forwarder-sent-audit-log-id
Jul 4, 2026
Merged

fix(worker): populate forwarder_sent.audit_log_id for UUID-shaped audit_ids#108
mastermanas805 merged 4 commits into
masterfrom
fix/forwarder-sent-audit-log-id

Conversation

@mastermanas805

Copy link
Copy Markdown
Member

Summary

  • Updates markSent in event_email_forwarder.go to populate audit_log_id when audit_id is UUID-shaped
  • Uses an inline CASE expression so placeholder IDs remain NULL without any Go-side parsing
  • Updates the TestForwarder_LedgerClaim_AllColumnsRoundtripThroughInsert mock expectation to match the new SQL

Why

Companion to api PR #289 (migration 072 adds forwarder_sent.audit_log_id UUID FK). Without this worker change, new rows would always have audit_log_id = NULL even when audit_id is a real UUID, defeating the purpose of the FK. Placeholder IDs (reminder-<resource_id>-<stage>, provider-<grace_id>) remain NULL — no behaviour change for legacy emitters.

Closes the P2 gap from CLAUDE.md: "worker event_email_forwarder must also populate audit_log_id for real-UUID audit_ids".

Test plan

  • go test ./internal/jobs/ -run TestForwarder — all pass
  • go build ./... — clean build

🤖 Generated with Claude Code

…it_ids (mig 072)

Companion to api mig 072 (forwarder_sent.audit_log_id UUID FK column).

markSent now includes audit_log_id in the INSERT column list and populates
it via an inline CASE expression:

  CASE WHEN $1 ~* '^[0-9a-f]{8}-...-[0-9a-f]{12}$'
       THEN $1::uuid
       ELSE NULL
  END

This means:
- Real UUID audit_ids (post-mig-063 rows from audit_log-backed emitters)
  → audit_log_id set; the orphan-reconciler can JOIN on the typed UUID column
  instead of scanning with a regex over TEXT.
- Placeholder IDs ("reminder-<resource_id>-<stage>", "provider-<grace_id>")
  → audit_log_id stays NULL; no behaviour change for those legacy emitters.

Test update: TestForwarder_LedgerClaim_AllColumnsRoundtripThroughInsert
updated to match the new column list + CASE expression in the INSERT regex.
@mastermanas805
mastermanas805 enabled auto-merge (rebase) July 4, 2026 09:29
@mastermanas805
mastermanas805 merged commit 007d1bb into master Jul 4, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant