Threadline.Capture.AuditChange (Threadline v0.12.0)

Copy Markdown View Source

Ecto schema for the audit_changes table.

An AuditChange records a single row-level mutation (INSERT, UPDATE, or DELETE) on an audited table. Records are created automatically by PostgreSQL triggers; you do not insert them from application code.

Each AuditChange belongs to exactly one AuditTransaction. Multiple changes in the same database transaction share a transaction_id.

Key fields

  • :table_schema / :table_name — the schema and table where the mutation occurred.
  • :table_pk — primary key of the mutated row, stored as a JSON map so composite keys are supported.
  • :op — "INSERT", "UPDATE", or "DELETE".
  • :data_after — full row snapshot after the mutation (nil for deletes).
  • :changed_fields — list of column names that changed (populated for updates; nil for inserts and deletes).
  • :changed_from — sparse JSON map of prior column values on UPDATE when a per-table opt-in capture function is installed; otherwise nil.
  • :captured_at — trigger execution timestamp (microsecond precision).

Relationships

  • belongs_to :transaction, Threadline.Capture.AuditTransaction — the DB transaction that produced this change.

Setup

Triggers are installed per table by mix threadline.gen.triggers, which emits SQL calling threadline_capture_changes() from mix threadline.install. See guides/domain-reference.md for the domain model for the capture contract.

Summary

Types

t()

One row mutation (INSERT, UPDATE, or DELETE) in one audited table.

Types

t()

@type t() :: %Threadline.Capture.AuditChange{
  __meta__: term(),
  captured_at: term(),
  changed_fields: term(),
  changed_from: term(),
  data_after: term(),
  id: term(),
  op: term(),
  table_name: term(),
  table_pk: term(),
  table_schema: term(),
  transaction: term(),
  transaction_id: term()
}

One row mutation (INSERT, UPDATE, or DELETE) in one audited table.