AuditTrail. Adapters. Postgres
(audit_trail v0.1.0)
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.migrateTable structure
The adapter writes to a table named audit_logs with these columns:
| Column | Type | Description |
|---|---|---|
id | bigserial | Auto-incrementing primary key |
event_id | text | UUID assigned at emit time |
event_type | text | e.g. "auth:login" |
actor_id | text | User ID or "anonymous" |
actor_name | text | Display name of the actor |
actor_email | text | Email of the actor |
payload | jsonb | Full structured event payload |
inserted_at | timestamptz | When the event was recorded |
A GIN index on payload enables efficient JSON field searches.