Mailglass.Migration (Mailglass v2.5.0)

Copy Markdown View Source

Public migration API for mailglass.

Adopters consume this via a single 8-line wrapper file that mix mailglass.gen.migration emits:

defmodule MyApp.Repo.Migrations.AddMailglass do
  use Ecto.Migration
  def up, do: Mailglass.Migration.up(repo: MyApp.Repo)
  def down, do: Mailglass.Migration.down(repo: MyApp.Repo)
end

The initial-install wrapper stays stable and transactional across mailglass versions. Populated upgrades generated with --upgrade use a separate transaction-disabled wrapper so new versions can build indexes concurrently. Per-version DDL lives in Mailglass.Migrations.Postgres.VNN modules, dispatched by Mailglass.Migrations.Postgres tracking the current version in the pg_class comment on mailglass_events.

Postgres-only at v0.1 per PROJECT.md (MySQL/SQLite out of scope).

Summary

Functions

Rolls back migrations down to the target version (default: 0).

Returns the currently-applied migration version (0 only when its anchor is absent).

Runs all pending migrations up to the latest version.

Types

version()

Functions

down(opts \\ [])

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

Rolls back migrations down to the target version (default: 0).

migrated_version(opts \\ [])

(since 0.1.0)
@spec migrated_version(keyword()) :: version()

Returns the currently-applied migration version (0 only when its anchor is absent).

This function is safe to call outside an Ecto.Migrator context — unlike up/1 / down/1, it does not rely on the migration runner process (it issues a single pg_catalog.obj_description query against the configured Repo and returns an integer). Raises Mailglass.MigrationVersionError when catalog metadata cannot be trusted.

up(opts \\ [])

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

Runs all pending migrations up to the latest version.