StatifierPersistence.Ecto.Config (StatifierPersistence v0.3.0)

Copy Markdown View Source

The resolved configuration behind use StatifierPersistence.Ecto.

ADR-0002 decision 3 requires that the generated schemas and the migrations helper take the same options and cannot disagree. This module is the single definition site that makes that true: __using__/1 builds a Config at the host's compile time, and the migrations helper reads the same struct (via for: HostModule) or funnels literal options through the same new/1.

Options:

  • :repo - required, the host's Ecto.Repo module
  • :key - the surrogate-key scheme, :uxid (default), :uuid, :bigserial, or {module, opts} implementing StatifierPersistence.Ecto.KeyGenerator
  • :table_prefix - prefix for the generated table names, default "statifier_"
  • :tables - per-table override map with keys :charts, :positions, :runs; an override replaces the whole name, prefix included
  • :prefix - the Postgres schema (Ecto's @schema_prefix), default nil
  • :blob_type - the Ecto type applied to the three blob columns (identity_blob, chart_blob, position_blob), default :binary (the built-in bytea behaviour, unchanged). Pass a module implementing Ecto.Type for field(name, Mod), or a {module, opts} tuple for an Ecto.ParameterizedType for field(name, Mod, opts) - the shape Ecto itself uses to declare a parameterized field. Keys and lookup columns (content_hash, session_id, run_id, status, failure) are never affected; only the three blob columns reach this option. Resolved and stored on the struct as :binary (bare) or {module, opts} (normalized, so a bare custom module becomes {module, []}) - one shape for downstream code to read.

Unknown options and unknown table keys raise ArgumentError - at the host's compile time when reached through use.

Summary

Types

t()

Resolved configuration for one host module.

Functions

The resolved field/3 arguments for a blob column under this configuration: [name, :binary] for the default, or [name, module, opts] for a custom :blob_type (opts is [] for a bare custom module, since field/3 treats an empty-opts parameterized call and a plain Ecto.Type call identically).

Validates and resolves the options use StatifierPersistence.Ecto accepts. Raises ArgumentError on anything malformed.

The table name (source) for table under this configuration: the per-table override when one was given, otherwise the table prefix plus the table's own name.

Types

t()

@type t() :: %StatifierPersistence.Ecto.Config{
  blob_type: :binary | {module(), keyword()},
  key: {module(), keyword()},
  prefix: String.t() | nil,
  repo: module(),
  table_prefix: String.t(),
  tables: %{
    optional(StatifierPersistence.Ecto.KeyGenerator.table()) => String.t()
  }
}

Resolved configuration for one host module.

Functions

blob_field_args(config, name)

@spec blob_field_args(t(), atom()) :: [term(), ...]

The resolved field/3 arguments for a blob column under this configuration: [name, :binary] for the default, or [name, module, opts] for a custom :blob_type (opts is [] for a bare custom module, since field/3 treats an empty-opts parameterized call and a plain Ecto.Type call identically).

new(opts)

@spec new(keyword()) :: t()

Validates and resolves the options use StatifierPersistence.Ecto accepts. Raises ArgumentError on anything malformed.

table(config, table)

The table name (source) for table under this configuration: the per-table override when one was given, otherwise the table prefix plus the table's own name.