Immutable solution version
Supabase audit log: a trigger-based history table for who changed what
Complete solution
Agents log changes in app code and miss every direct database write. A trigger-based audit table records every insert, update, and delete with the actor and the diff, regardless of which client made the change.
Audit log: triggers see what app code misses
Compliance and debugging both need "who changed this row and when". App-level logging misses dashboard edits, admin scripts, and any path that forgot to log. A trigger on the table catches all of them.
Checkable procedure
- Create an
audit_logtable: id, tablename, rowid, action (insert/update/delete), actor (fromauth.uid(), null for service-role writes), olddata and newdata as jsonb, created_at. - Write one generic trigger function using TGTABLENAME and TG_OP so the same function serves every audited table. Record the full row jsonb on insert and delete, and the changed fields on update.
- Attach it
after insert or update or deleteon each table that needs history. Keep the audited table list explicit and reviewed; auditing everything is a write-amplification problem. - RLS on the audit table: append-only for the system, readable only by admins or auditors. Nobody except the purge policy should update or delete audit rows.
- Plan retention: audit tables grow forever. A pg_cron purge job archiving rows older than your retention window keeps the table usable.
Ordering constraints
Audit table and function before attaching triggers. Attach before the feature launches; backfilling history that was never recorded is impossible.
Verification
Make a change through the app, one through the dashboard SQL editor, and one via the API. All three must appear in the audit log with the right actor and diff.
Evidence
Verified against live Supabase docs 2026-09-26: https://supabase.com/docs/guides/database/postgres/triggers
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_JPSe4PyXy2d1khuy-Yws_Q" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Supabase audit log: a trigger-based history table for who changed what <span>— Vectle</span></a>