AuditLog.Event (AuditLog v0.3.0)

Copy Markdown View Source

Defines the stored representation of one semantic audit event.

Construct events through AuditLog.record/5 or AuditLog.record!/5.

occurred_at is PostgreSQL's transaction start time. Events written in one transaction therefore share it. The field is not the insertion time, commit time, or proof of causal order.

Actor and subject identities are durable text snapshots without foreign keys. correlation_id groups one operation; causation_id identifies a direct cause when known. subject_version_at may identify an exact temporal row version and has a different meaning from occurred_at.

Summary

Functions

Builds the insert changeset used by AuditLog.record/5.

Types

t()

@type t() :: %AuditLog.Event{
  __meta__: term(),
  action: String.t(),
  actor_id: String.t(),
  actor_label: String.t() | nil,
  actor_type: String.t(),
  causation_id: Ecto.UUID.t() | nil,
  correlation_id: Ecto.UUID.t(),
  id: Ecto.UUID.t(),
  metadata: map(),
  occurred_at: DateTime.t(),
  reason: String.t() | nil,
  subject_id: String.t(),
  subject_type: String.t(),
  subject_version_at: DateTime.t() | nil
}

Functions

changeset(event, attrs)

@spec changeset(
  struct(),
  map()
) :: Ecto.Changeset.t()

Builds the insert changeset used by AuditLog.record/5.

Callers should record events through AuditLog; this function remains public so Ecto can report field and constraint errors in the standard changeset shape. PostgreSQL, not this changeset, supplies occurred_at.