mix threadline.gen.triggers (Threadline v0.5.0)

Copy Markdown View Source

Generates an Ecto migration that installs Threadline audit triggers on the specified tables.

Usage

mix threadline.gen.triggers --tables users
mix threadline.gen.triggers --tables users,posts,comments

Each invocation produces one migration file containing CREATE TRIGGER statements for all listed tables. Run mix ecto.migrate to apply.

The trigger calls threadline_capture_changes(), which must already be installed via mix threadline.install.

With before-values capture for opted-in tables:

mix threadline.gen.triggers --tables posts --store-changed-from
mix threadline.gen.triggers --tables posts --store-changed-from --except-columns secret_token,internal_score

That emits per-table functions threadline_capture_changes_<table>() and wires triggers to them. Migrations generated without --store-changed-from keep the default global threadline_capture_changes() trigger body unless the table has :exclude / :mask rules under config :threadline, :trigger_capture (see README).

Redaction (config :threadline, :trigger_capture)

At task start the host app config is loaded (Mix.Task.run("app.config", [])). Per-table entries under :tables may set :exclude, :mask, optional :mask_placeholder, :store_changed_from, and :except_columns. Overlap between :exclude and :mask is validated with Threadline.Capture.RedactionPolicy before writing the migration.

Options

  • --tables — comma-separated list of table names (required)
  • --store-changed-from — emit per-table capture functions that persist sparse changed_from JSON on UPDATE (default: off)
  • --except-columns — comma-separated column names excluded from both changed_fields and changed_from when --store-changed-from is set (alphanumeric and underscore only). Merged with :except_columns from config.
  • --dry-run — print table=… exclude=… mask=… per table and skip writing a migration

Guards

The task exits non-zero if audit_transactions or audit_changes is in the table list. Installing audit triggers on Threadline's own tables would cause recursive loops (D-10, CAP-10).