Arcadic.Migrator (Arcadic v0.1.0)

Copy Markdown View Source

Runs Arcadic.Migrations in order and tracks applied versions in the _arcadic_migrations document type. Tenant-blind: it runs DDL/DML and records integer versions — no tenant, scope, or Ash concept. Assumes single-process, deploy-time execution (like every migration tool); it does not take an advisory lock, so do not run two migrators concurrently against one database.

Summary

Functions

Run all pending migrations (up). Returns {:ok, count_run}.

Registered migrations not yet applied, ascending by version (pure).

Roll back every applied migration, then migrate all. Returns {:ok, migrated_count}.

Roll back the last n applied migrations (down), newest first. Returns {:ok, count}.

Status of each registered migration: {version, :up | :down}, ascending.

Functions

migrate(conn, registry)

@spec migrate(Arcadic.Conn.t(), module()) ::
  {:ok, non_neg_integer()} | {:error, Exception.t()}

Run all pending migrations (up). Returns {:ok, count_run}.

pending_migrations(mods, applied)

@spec pending_migrations([module()], [integer()]) :: [module()]

Registered migrations not yet applied, ascending by version (pure).

reset(conn, registry)

@spec reset(Arcadic.Conn.t(), module()) ::
  {:ok, non_neg_integer()} | {:error, Exception.t()}

Roll back every applied migration, then migrate all. Returns {:ok, migrated_count}.

rollback(conn, registry, n \\ 1)

@spec rollback(Arcadic.Conn.t(), module(), pos_integer()) ::
  {:ok, non_neg_integer()} | {:error, Exception.t()}

Roll back the last n applied migrations (down), newest first. Returns {:ok, count}.

status(conn, registry)

@spec status(Arcadic.Conn.t(), module()) ::
  {:ok, [{pos_integer(), :up | :down}]} | {:error, Exception.t()}

Status of each registered migration: {version, :up | :down}, ascending.