StatifierPersistence. Ecto. KeyGenerator behaviour
(StatifierPersistence v0.1.0)
Copy Markdown
View Source
Behaviour a surrogate-key scheme implements for the Ecto layer.
ADR-0002 makes the surrogate primary keys of this package's tables
compile-time configurable per host: :uxid (the default), :uuid
(UUIDv7), :bigserial, or any {module, opts} implementing this
behaviour. A key scheme must answer three questions - the Ecto schema
field type, the migration column type, and how a key is generated (or
that the database assigns it) - and both the generated schemas and the
migrations helper read their answers from the same resolved generator,
so the two cannot disagree.
Engine identities (the chart content hash, the engine session id, the caller's run id) are stored verbatim and are not touched by any key generator - ADR-0002 decision 1.
The bundled implementations:
StatifierPersistence.Ecto.KeyGenerator.UXID- k-sortable strings with per-table prefixes (chart_,pos_,run_)StatifierPersistence.Ecto.KeyGenerator.UUIDv7- RFC 9562 UUIDv7StatifierPersistence.Ecto.KeyGenerator.Bigserial- database-assigned auto-increment
Summary
Callbacks
The {module, function, args} an Ecto schema uses to autogenerate a
primary key for a row of table, or nil when the database assigns
the key itself.
The Ecto schema field type for the primary key, e.g. :string,
Ecto.UUID, or :id.
The column type the migrations helper emits for the primary key, e.g.
:text, :uuid, or :bigserial.
Functions
Resolves one of ADR-0002's key option spellings to {module, opts}.
Types
Callbacks
The {module, function, args} an Ecto schema uses to autogenerate a
primary key for a row of table, or nil when the database assigns
the key itself.
The Ecto schema field type for the primary key, e.g. :string,
Ecto.UUID, or :id.
The column type the migrations helper emits for the primary key, e.g.
:text, :uuid, or :bigserial.
Functions
Resolves one of ADR-0002's key option spellings to {module, opts}.
:uxid, :uuid, and :bigserial map onto the bundled
implementations. A {module, opts} tuple passes through after a check
that module declares this behaviour; anything else raises
ArgumentError.