PgFlow.Migration (PgFlow v0.1.0)

Copy Markdown View Source

Installs the pgflow core schema (tables, triggers, functions) into a consumer app's database via EctoEvolver.

Usage (consumer side)

A consumer uses mix pgflow.setup to generate a wrapper migration:

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

  def up do
    PgFlow.Migration.up()
    PgFlow.HelpersMigration.up()
  end

  def down do
    PgFlow.HelpersMigration.down()
    PgFlow.Migration.down()
  end
end

Prerequisites

This migration assumes the following are already in place in the target DB:

  • pgmq schema and its functions (install via mix pgflow.gen.pgmq_migration)
  • pg_cron extension registered (CREATE EXTENSION pg_cron)
  • Standard Postgres extensions: citext, pg_trgm, pgcrypto

Ordering: the prerequisites above must be applied first (separate migrations). The typical project-level order is postgres_extensions → pgmq → pgflow.setup, where setup bundles a wrapper migration that runs PgFlow.Migration.up/0 then PgFlow.HelpersMigration.up/0 in one transaction.

Schema prefix

The SQL bundle hardcodes "pgflow" as the schema name (matching upstream conventions). default_prefix: "pgflow" is fixed; runtime prefix override via up(prefix: ...) is not supported by this version because it would require rewriting every qualified reference in the vendored SQL. If the library later needs multi-tenant schema prefixes, regenerate the bundle with $SCHEMA$ placeholders.

Versioning

New upstream pgflow releases become V02, V03, ... — each a delta from the previous version. V01 is never rewritten; existing deployments apply only new versions on upgrade.

Legacy install detection

up/1 refuses to run V01 DDL against a schema that already contains pgflow tables but is missing EctoEvolver's tracking comment — a restored dump that lost comments, a manual psql seed, or any schema not installed by PgFlow.Migration.up/0 itself. The raised error points the operator at mix pgflow.stamp, which adopts the existing schema into the tracking model without re-running the bundle.

Summary

Functions

See PgFlow.Migration.Evolver.current_version/0.

See PgFlow.Migration.Evolver.down/1.

See PgFlow.Migration.Evolver.migrated_version/1.

Installs or upgrades the pgflow schema to the latest version.

Functions

current_version()

See PgFlow.Migration.Evolver.current_version/0.

down(opts \\ [])

See PgFlow.Migration.Evolver.down/1.

migrated_version(opts \\ [])

See PgFlow.Migration.Evolver.migrated_version/1.

up(opts \\ [])

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

Installs or upgrades the pgflow schema to the latest version.

Options:

  • :prefix — schema prefix (default "pgflow").
  • :version — target version (default: latest).

Raises if the target schema already contains pgflow tables without an EctoEvolver tracking comment — see "Legacy install detection" above.