CouncilEx.Registry.Ecto (CouncilEx v0.1.0)

Copy Markdown View Source

Ecto-backed CouncilEx.Registry runtime registrations. Multi-replica safe.

Tested on Postgres via :postgrex. The portable INSERT ... ON CONFLICT DO UPDATE SQL also runs on SQLite (3.24+) via :ecto_sqlite3; column types are kept generic so other Ecto SQL adapters should work without changes.

Uses your application's existing Ecto.Repo (no extra connection pool). Stored values are :erlang.term_to_binary/1 blobs decoded with binary_to_term/2 in :safe mode — atoms (including module names) must already exist on the deserializing node.

Setup

config :council_ex,
  :registry_backend,
  CouncilEx.Registry.Ecto

config :council_ex, CouncilEx.Registry.Ecto,
  repo: MyApp.Repo,
  table: "council_ex_registry"

:repo is required. :table defaults to "council_ex_registry".

Migration

Use CouncilEx.Persistence.Migration — see its moduledoc. The :registry component creates the council_ex_registry table (or <your_prefix>registry if you override :table_prefix).

Limitations

  • Anonymous closures with captured environment cannot survive term_to_binary round-trips reliably. Prefer remote captures (&MyApp.Mod.fun/1) for :input_mapper registrations.
  • Atoms not present on the deserializing node crash decode. Keep registered modules in the codebase (same release across replicas).
  • Failed DB operations return {:error, reason} from put/3, delete/2, and reset/0; get/2 and all/1 return nil / %{} on failure (cold-start fallback).