Chronicle.Version (chronicle v0.1.0)

Copy Markdown

One immutable, signed version of an Ecto record.

A version holds only what describes the version itself: where it sits in the record's history, what kind of change it was, and whether the record can be reconstructed from it.

%Chronicle.Version{
  version: 3,
  operation: :update,
  schema: MyApp.Account,
  record: %MyApp.Account{},
  restorable?: true
}

version is the record-local, one-based position in committed ledger order. A deleted version is a tombstone: operation is :delete and record is nil.

Everything describing the event — actor, subject, changes, timestamp, correlation id, group id, metadata — lives on event, and only there. No value appears in two places. operation and schema are typed readings of event.action and event.subject, not copies of them:

version.event.actor
version.event.changes
version.event.occurred_at
version.event.subject["id"]

Summary

Functions

Returns the field transitions recorded for a version.

Returns the stored snapshot for a version.

Types

t()

@type t() :: %Chronicle.Version{
  event: Chronicle.Event.t(),
  missing_fields: [atom()],
  operation: :insert | :update | :delete,
  reconstruction_error: term() | nil,
  record: struct() | nil,
  restorable?: boolean(),
  schema: module(),
  version: pos_integer()
}

Functions

changes(version)

@spec changes(t()) :: [map()]

Returns the field transitions recorded for a version.

snapshot(version)

@spec snapshot(t()) :: map() | nil

Returns the stored snapshot for a version.

The snapshot is held once, inside the signed event payload.