Generates PL/pgSQL trigger DDL for Threadline audit capture.
The trigger function uses txid_current() to group row changes from the same
database transaction under a single audit_transactions row. This approach is
transaction-pooling safe per D-06: no session-local configuration writes.
Optional audit_transactions.actor_ref is read from the transaction-local GUC
threadline.actor_ref (published by the host application in the same
transaction — see D-09); the trigger only reads this setting and never
assigns session configuration from PL/pgSQL. The txid column on audit_transactions has a UNIQUE
constraint so concurrent INSERTs with ON CONFLICT DO NOTHING are safe.
Before-values (changed_from)
The default threadline_capture_changes() always writes changed_from as SQL
NULL. To capture sparse prior-row JSON on UPDATE for specific tables, generate a
migration with mix threadline.gen.triggers --tables ... --store-changed-from
(and optional --except-columns col1,col2). That emits a per-table function
threadline_capture_changes_<table>() and rewires triggers to call it.
Redaction (:exclude / :mask)
When non-empty column lists are passed to install_function/1 or
install_function_for_table/2, keys are removed (:exclude) or replaced with a
stable placeholder (:mask) in data_after (and in changed_from when
enabled). except_columns (per-table only) still removes keys from
changed_fields / changed_from only; exclude also strips keys from the
full-row data_after JSON. Union of both applies to change detection.
json / jsonb columns: masking replaces the entire column value with the placeholder (no deep redaction).
Summary
Functions
Returns SQL to install a trigger on the given table.
Returns SQL to drop the global trigger function.
Returns SQL to drop a per-table capture function (use after dropping triggers, or with CASCADE).
Returns SQL to drop a trigger from the given table.
Returns SQL to create or replace the threadline_capture_changes() trigger function.
Returns SQL to create or replace threadline_capture_changes_<table>() with
UPDATE-time sparse changed_from built from OLD for keys in changed_fields
(after except_columns and exclude are removed). Requires store_changed_from: true
or non-empty :exclude / :mask.
Functions
Returns SQL to install a trigger on the given table.
:default— callsthreadline_capture_changes()(default).:per_table— callsthreadline_capture_changes_<table>()frominstall_function_for_table/2.
Returns SQL to drop the global trigger function.
Returns SQL to drop a per-table capture function (use after dropping triggers, or with CASCADE).
Returns SQL to drop a trigger from the given table.
Returns SQL to create or replace the threadline_capture_changes() trigger function.
The function assumes audit_transactions and audit_changes tables are accessible
via the current search_path. changed_from is always written as NULL (use
install_function_for_table/2 for opt-in prior values).
Options
:exclude— column names omitted entirely fromdata_afterand fromchanged_fields.:mask— column names whose values become the placeholder indata_after(after excludes).:mask_placeholder— optional string; validated viaRedactionPolicy(default"[REDACTED]").
When both lists are empty, SQL is identical to the historical global function.
Returns SQL to create or replace threadline_capture_changes_<table>() with
UPDATE-time sparse changed_from built from OLD for keys in changed_fields
(after except_columns and exclude are removed). Requires store_changed_from: true
or non-empty :exclude / :mask.
Options
:store_changed_from— when true, populatechanged_fromon UPDATE.:except_columns— omit fromchanged_fields/changed_from(does not strip fromdata_after).:exclude,:mask,:mask_placeholder— same semantics asinstall_function/1for row JSON.