# `Mailglass.Migration`
[🔗](https://github.com/szTheory/mailglass/blob/v2.7.0/lib/mailglass/migration.ex#L1)

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).

# `version`

```elixir
@type version() :: Mailglass.Migrations.Postgres.version()
```

# `down`
*since 0.1.0* 

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

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

# `migrated_version`
*since 0.1.0* 

```elixir
@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`
*since 0.1.0* 

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

Runs all pending migrations up to the latest version.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
