Threadline.StorageSchema (Threadline v1.0.0)

Copy Markdown View Source

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.

Summary

Types

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

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

Repository options targeting the Threadline storage schema.

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).

Functions

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

Returns Ecto repository options that target Threadline-owned storage.

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

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

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

Types

identifier_input()

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

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

parsed_table_identifier()

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

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

repo_opts_result()

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

Repository options targeting the Threadline storage schema.

role()

@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).

Functions

get(opts \\ [])

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(opts \\ [])

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(name, opts \\ [])

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?(value)

@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!(value)

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

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