Reads deterministic ordering keys from a Postgres database.
fetch!/1 returns unique database column sets keyed by
{database_schema, table}:
%{
{"public", "posts"} => [
["id"],
["slug"],
["organisation_id", "sequence"]
]
}Tables visible through the current Postgres search path also receive a
{nil, table} entry. This lets unprefixed Ecto queries use the same catalogue
without assuming that the visible schema is public.
The catalogue includes primary keys and valid, immediate, full-table unique
indexes over plain columns. Nullable unique keys are included only when every
key column is NOT NULL or the index uses NULLS NOT DISTINCT.
Partial indexes, expression indexes, invalid indexes, deferrable uniqueness, non-default operator classes, and non-default collations are excluded because they do not conservatively prove that a plain Ecto field ordering is unique.
The functions are stateless. Every invocation performs one Postgres catalogue query.
Summary
Types
Verified unique keys keyed by database schema and table.
Option accepted by fetch!/2.
Options accepted by fetch!/2.
Database columns that together form one verified unique key.
Functions
Fetches verified unique keys from one Postgres repo.
Fetches verified unique keys from one Postgres repo with options.
Types
@type catalogue() :: %{optional({String.t() | nil, String.t()}) => [unique_key()]}
Verified unique keys keyed by database schema and table.
A nil database schema represents an unqualified table visible through the
current Postgres search path.
Option accepted by fetch!/2.
@type fetch_opts() :: [fetch_opt()]
Options accepted by fetch!/2.
@type unique_key() :: [String.t(), ...]
Database columns that together form one verified unique key.
Functions
Fetches verified unique keys from one Postgres repo.
Raises when the repo cannot be inspected or returns malformed catalogue data.
@spec fetch!(repo :: module(), opts :: fetch_opts()) :: catalogue()
Fetches verified unique keys from one Postgres repo with options.
The only supported option is :dynamic_repo. Pass a dynamic repo name or PID
to run the catalogue query against that repo. The previously selected dynamic
repo is restored after the query.