Mediate.Postgres.Catalog (mediate_postgres v0.1.0)

Copy Markdown View Source

What the database says its own rules are.

read!/1 asks three sources:

  • pg_policy, for every policy on the bound tables, with the USING and WITH CHECK expressions as pg_get_expr/2 renders them
  • pg_depend, for the columns those expressions reference
  • the migrations table, for the highest version, which is the version a decision names

load!/1 reads once per binding and keeps the result for the life of the VM. So no call on the request path pays for a catalog read. The query counts of a mediated call stay what the shape tests expect. An application loads it at boot through Mediate.Postgres.load!/0, after the binding. current!/1 loads on first use for a caller that did not. A migration that runs while the VM is up leaves the kept catalog behind the database, so reload!/1 reads it again and replaces it.

Every statement runs through the bound repo's raw channel under the library exemption, so the seam mediates a catalog read like any other call.

Summary

Types

t()

The version, the policies of the bound tables, and the table and column of every read they make.

Functions

The loaded catalog. A first call loads it.

The gate policy of an operation on a table, or nil.

Read the catalog once for this binding and keep it. A second call reads nothing.

The policies on those tables, as pg_policy holds them, for a caller with no binding yet.

Read the catalog now, whatever a previous call loaded.

Read the catalog again and keep what it says now. A migration that runs after boot changes the policies and the version under a loaded catalog. Every call after the reload reads the ones the database now holds.

The scope policy of an operation on a table, or nil.

The policies as the text a policy version carries.

Types

t()

@type t() :: %Mediate.Postgres.Catalog{
  columns: [{String.t(), String.t()}],
  policies: [Mediate.Postgres.Policy.t()],
  version: String.t()
}

The version, the policies of the bound tables, and the table and column of every read they make.

Functions

current!(binding)

@spec current!(Mediate.Postgres.Binding.t()) :: t()

The loaded catalog. A first call loads it.

gate(catalog, table, operation)

@spec gate(t(), String.t(), atom()) :: Mediate.Postgres.Policy.t() | nil

The gate policy of an operation on a table, or nil.

load!(binding)

@spec load!(Mediate.Postgres.Binding.t()) :: t()

Read the catalog once for this binding and keep it. A second call reads nothing.

policies!(repo, tables)

@spec policies!(module(), [String.t()]) :: [Mediate.Postgres.Policy.t()]

The policies on those tables, as pg_policy holds them, for a caller with no binding yet.

read!(binding)

@spec read!(Mediate.Postgres.Binding.t()) :: t()

Read the catalog now, whatever a previous call loaded.

reload!(binding)

@spec reload!(Mediate.Postgres.Binding.t()) :: t()

Read the catalog again and keep what it says now. A migration that runs after boot changes the policies and the version under a loaded catalog. Every call after the reload reads the ones the database now holds.

scope(catalog, table, operation)

@spec scope(t(), String.t(), atom()) :: Mediate.Postgres.Policy.t() | nil

The scope policy of an operation on a table, or nil.

to_text(policies)

@spec to_text([Mediate.Postgres.Policy.t()]) :: String.t()

The policies as the text a policy version carries.