# `StatifierPersistence.Ecto.Config`
[🔗](https://github.com/riddler/statifier_persistence/blob/v0.13.0/lib/statifier_persistence/ecto/config.ex#L1)

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`, `:executions`, `:inputs`; 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 payload blob columns
    (`identity_blob`, `chart_blob`, `position_blob`, `outcome_blob`,
    and `input_blob` since ADR-0010 decision 4), 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`, `execution_id`, `status`, `failure`, `seq`, `door`) are
    never affected; only the payload 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`.

# `t`

```elixir
@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()) =&gt; String.t()
  }
}
```

Resolved configuration for one host module.

# `blob_field_args`

```elixir
@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`

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

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

# `table`

```elixir
@spec table(t(), StatifierPersistence.Ecto.KeyGenerator.table()) :: String.t()
```

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.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
