# `Threadline.StorageSchema`
[🔗](https://github.com/szTheory/threadline/blob/v1.2.0/lib/threadline/storage_schema.ex#L1)

Resolves storage schema names and builds validated SQL references to Threadline-owned tables.

`get/1` and `repo_opts/1` apply schema configuration, `table/2` names a
Threadline table, `validate!/1` checks an identifier, and `threadline_table?/1`
recognizes Threadline table names.

Threadline defaults to the host's `public` schema — the schema every install
that predates this module already uses. Threadline cannot detect where an
existing install put its audit tables, so the default has to be the one that
is true for installs that already exist.

A dedicated schema is an explicit opt-in, and is the recommended choice for a
NEW install:

    config :threadline, storage_schema: "threadline"

Any other single-segment PostgreSQL identifier works too (`"audit"`, for
example). The choice is frozen at migration-generation time: the generated
triggers and tables are written into whichever schema was configured when
`mix threadline.install` ran, so changing the key afterwards requires a
migration, not just a config edit.

# `identifier_input`

```elixir
@type identifier_input() :: String.t() | atom()
```

An identifier accepted for schema validation; booleans and malformed names raise.

# `parsed_table_identifier`

```elixir
@type parsed_table_identifier() :: %{schema: String.t(), table: String.t()}
```

A parsed host table identifier with validated schema and table names.

# `repo_opts_result`

```elixir
@type repo_opts_result() :: [{:prefix, String.t()}]
```

Repository options targeting the Threadline storage schema.

# `role`

```elixir
@type role() ::
  :storage_schema | :host_schema | :host_table | :derived | :primary_key_column
```

Selects the identifier-validation context: `:storage_schema` (storage schema), `:host_schema` (host schema), `:host_table` (host table), `:derived` (derived identifier), or `:primary_key_column` (primary key column).

# `get`

```elixir
@spec get([Threadline.storage_schema_opt()]) :: String.t()
```

Returns the configured storage schema, defaulting to the host's `public` schema.

A dedicated schema is opted into with
`config :threadline, storage_schema: "threadline"`, or per-call via the
`:storage_schema` option.

## Options

- `:storage_schema` — string. Optional. Overrides the application setting.

## Returns

- The validated storage schema name.
- Raises `ArgumentError` when the configured name is invalid.

Other option keys are ignored.

# `repo_opts`

```elixir
@spec repo_opts([Threadline.storage_schema_opt()]) :: repo_opts_result()
```

Returns Ecto repository options that target Threadline-owned storage.

## Options

- `:storage_schema` — string. Optional. Selects the configured storage schema.

## Returns

- A `:prefix` option containing the validated Threadline storage schema.
- Raises `ArgumentError` when the selected storage schema is invalid.

Other option keys are ignored.

# `table`

```elixir
@spec table(String.t(), [Threadline.storage_schema_opt()]) :: String.t()
```

Returns a schema-qualified SQL name for one of Threadline's storage tables.

The accepted names are `audit_transactions`, `audit_changes`,
`audit_actions`, `threadline_export_jobs`, `threadline_retention_runs`,
`threadline_saved_views`, and `threadline_evidence_records`.

## Options

- `:storage_schema` — string. Optional. Selects the configured storage schema.

## Returns

- The quoted, schema-qualified table name.
- Raises `FunctionClauseError` when `name` is not one of the Threadline tables.
- Raises `ArgumentError` when the selected storage schema is invalid.

Other option keys are ignored.

# `threadline_table?`

```elixir
@spec threadline_table?(String.t()) :: boolean()
```

Returns whether a valid host table identifier names one of Threadline's storage tables; raises `ArgumentError` for malformed identifiers.

# `validate!`

```elixir
@spec validate!(identifier_input()) :: String.t()
```

Validates a PostgreSQL identifier and returns its trimmed name; raises `ArgumentError` for an invalid identifier.

---

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