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

Public migration API for mailglass_inbound.

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

    defmodule MyApp.Repo.Migrations.MailglassInboundInstall do
      use Ecto.Migration
      def up, do: MailglassInbound.Migration.up()
      def down, do: MailglassInbound.Migration.down()
    end

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

Postgres-only at v2.0 per PROJECT.md (MySQL/SQLite out of scope).
Inbound maintains its own independent version anchor — separate from core's
`mailglass_events` anchor — so both packages can evolve independently even in
a shared schema.

# `down`
*since 2.0.0* 

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

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

# `migrated_version`
*since 2.0.0* 

```elixir
@spec migrated_version(keyword()) :: 0 | 1 | 2
```

Returns the currently-applied inbound 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_class query against the configured Repo
and returns an integer). Raises `Mailglass.MigrationVersionError` when catalog
metadata cannot be trusted. Anchored on `mailglass_inbound_records`, not
`mailglass_events` — the two packages maintain independent version lines.

# `up`
*since 2.0.0* 

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

Runs all pending inbound migrations up to the latest version.

---

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