AuditTrail.Adapters.Postgres (audit_trail v0.1.1)

Copy Markdown

Storage adapter that persists audit logs to a PostgreSQL table.

Setup

1. Configure

config :audit_trail,
  storage_adapter: {AuditTrail.Adapters.Postgres, repo: MyApp.Repo}

2. Generate and run the migration

mix audit_trail.gen.migration
mix ecto.migrate

Table structure

The adapter writes to a table named audit_logs with these columns:

ColumnTypeDescription
idbigserialAuto-incrementing primary key
event_idtextUUID assigned at emit time
event_typetexte.g. "auth:login"
actor_idtextUser ID or "anonymous"
actor_nametextDisplay name of the actor
actor_emailtextEmail of the actor
payloadjsonbFull structured event payload
inserted_attimestamptzWhen the event was recorded

A GIN index on payload enables efficient JSON field searches.