StatifierRouter.Migrations (StatifierRouter v0.3.0)

Copy Markdown View Source

Versioned migrations for this package's tables, in the shape statifier_persistence's StatifierPersistence.Ecto.Migrations uses: the host writes one ordinary migration that delegates here, and later package versions ship higher-numbered migration modules the same call picks up.

defmodule MyApp.Repo.Migrations.AddStatifierRouter do
  use Ecto.Migration

  def up, do: StatifierRouter.Migrations.up(prefix: "routing")
  def down, do: StatifierRouter.Migrations.down(prefix: "routing")
end

The options are the two storage options of StatifierRouter.Config, :table_prefix and :prefix, resolved the same way, plus :from and :version:

  • :table_prefix - a string prefixed to every table name, default "statifier_router_". Pass the same value the host's StatifierRouter.Config carries.
  • :prefix - the Postgres schema the tables live in, default nil. When it is set, up/1 creates the schema if it does not exist and down/1 leaves it in place: dropping a schema the host may share is not this package's call.
  • :from and :version - where a call starts and where it ends, in both directions. up/1 migrates from from: (default: V01) up through version: (default: the newest this package knows), and down/1 rolls back from from: (default: the newest) down through version: (default: V01, that is, everything).

A host already running an older version writes its next migration with from: set to the first version it has not run, rather than re-running V01's CREATE TABLE against tables that already exist. A host whose first migration is capped with version: N caps its rollback to match with from: N.

A fault in the options raises ArgumentError: a migration has no caller to hand an {:error, reason} to.

StatifierRouter.Migrations.V01 records what the first version creates, and StatifierRouter.Migrations.V02 what the second adds.

:from is inclusive: up(from: 2) runs V02, and a host already on V01 that writes it gets the subscription table without V01's CREATE TABLE running a second time (ADR-0007, section 6).

Summary

Functions

Rolls the tables back from from: (default: the newest version this package knows) down through version: (default: V01, that is, everything).

Migrates the tables from from: (default: V01) up through version: (default: the newest).

Functions

down(opts \\ [])

@spec down(keyword()) :: :ok

Rolls the tables back from from: (default: the newest version this package knows) down through version: (default: V01, that is, everything).

up(opts \\ [])

@spec up(keyword()) :: :ok

Migrates the tables from from: (default: V01) up through version: (default: the newest).