StatifierRouter.Migrations.V01 (StatifierRouter v0.9.2)

Copy Markdown View Source

V01 of the package DDL: the three tables the decision records fix, each named by StatifierRouter.Config.table/2 under the host's table prefix and created in the host's Postgres schema when one is set.

addresses (ADR-0002, section 1): (scope, document, key) -> execution_id.

ColumnTypeNull
idbigserial, primary keyno
scopetextno
documenttextno
keytextno
execution_idtextno
inserted_atutc_datetime_usecno
terminal_seen_atutc_datetime_usecyes, empty until the execution is first seen terminal

Indexes: the unique <table>_scope_document_key_index on (scope, document, key), and <table>_execution_id_index on execution_id, so the rows naming one execution are found without a scan.

dedupe (ADR-0003, section 6): one row per (binding_id, message_id) a delivery got past the dedupe step with.

ColumnTypeNull
idbigserial, primary keyno
binding_idtextno
message_idtextno
expires_atutc_datetime_usecno

Indexes: the unique <table>_binding_id_message_id_index on (binding_id, message_id), and <table>_expires_at_index on expires_at, for the reaper that deletes expired rows.

routing_ledger (ADR-0004, section 4): append-only, one row per recorded outcome.

ColumnTypeNull
idbigserial, primary keyno
binding_idtextno
message_idtextno
scopetextno
outcometextno
keytextyes, empty for key_refused
execution_idtextyes, empty where the outcome names no execution
reasontextyes, empty for every outcome but key_refused
inserted_atutc_datetime_usecno

Index: <table>_binding_id_inserted_at_index on (binding_id, inserted_at), since the ledger is read per binding.

The tables above are the layout with no layout option set. The StatifierRouter.Migrations layout options reshape them only as this version creates them: :leading_columns go immediately after id on all three, timestamps_position: :leading moves inserted_at to follow them on the two tables that have one, and :column_collations declares each named text column with its collation wherever a table here has it.

The id above is the host repo's implicit primary key, a bigserial unless the repo's :migration_primary_key says otherwise. Under the StatifierRouter.Migrations :primary_key option it is instead an id of the type and default the option names, on all three tables.

Summary

Types

The resolved storage and layout options StatifierRouter.Migrations hands each version.

Functions

Drops the V01 tables in reverse creation order; the Postgres schema stays.

Creates the V01 tables and their indexes.

Types

storage()

@type storage() :: %{
  :table_prefix => String.t(),
  :prefix => String.t() | nil,
  optional(:leading_columns) => [{atom(), {term(), keyword()}}],
  optional(:timestamps_position) => :trailing | :leading,
  optional(:column_collations) => [{atom(), String.t()}],
  optional(:primary_key) => keyword() | nil
}

The resolved storage and layout options StatifierRouter.Migrations hands each version.

Functions

down(map)

@spec down(storage()) :: :ok

Drops the V01 tables in reverse creation order; the Postgres schema stays.

up(storage)

@spec up(storage()) :: :ok

Creates the V01 tables and their indexes.