mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-05 14:14:39 +00:00
The DEFAULT 'unknown' added in the last pass stopped a previous-release process from raising NotNullViolation mid-rollout, but it threw the attribution away to do it. The highest-volume auth_events writers are OIDC login and silent renewal, where the actor is simply the user, so a rollout window would have flattened exactly the rows that were trivially recoverable. Lifts both derivation rules into SQL functions -- auth_events_derive_actor and auth_events_derive_target -- so the backfill and a BEFORE INSERT trigger share one definition rather than two copies of the same CASE drifting apart. The trigger guards on NEW.actor_id IS NULL, which identifies a legacy insert exactly because the repository always supplies one. That distinction matters for target_id: a current writer sets it NULL deliberately for events with no user target, and deriving there would name the actor as their own target. Kept rather than scheduled for removal: it is a no-op on the path the repository takes, and it keeps the column's contract true for any writer that bypasses it.