# `PhoenixMountable.Migrations.Test`
[🔗](https://github.com/hattoriai/phoenix_mountable/blob/v0.2.1/lib/phoenix_mountable/migrations/test.ex#L2)

Checks for a library's migrations, run against a real database in the
library's own test suite.

    test "migrations", %{repo: repo} do
      PhoenixMountable.Migrations.Test.run_suite(repo, MyLib.Migrations, prefix: "my_lib_test")
    end

`run_suite/3` runs:

  * `assert_round_trip/3` — every version goes up, down and up again, and
    down gives back exactly the previous schema;
  * `assert_baseline_matches/3` — when the library has a baseline, a fresh
    install through it gives the same schema as running every version;
  * `assert_upgrades/3` — an install at each released version upgrades to
    the latest and ends with the same schema as a fresh install;
  * `assert_preserves_host_changes/3` — the "hostile host": after each
    version, a column and an index are added to every library table, as a
    host might, and they must survive every later version.

and, with `idempotent: true` (recommended for MySQL, whose DDL is not
transactional), `assert_rerunnable/3`: each version can run again after
failing halfway.

Each check starts from an empty schema: a Postgres schema or MySQL database
named by `:prefix` (dropped and recreated), or an emptied SQLite database.
Use a database and prefix reserved for these tests.

## Options

  * `:prefix` — the prefix to use. Defaults to `"phoenix_mountable_test"`
    (ignored on SQLite).
  * `:install` — install options for `up/1`, such as `primary_key: :binary_id`.
  * `:seed` — `fn version, ctx -> ... end`, run by `assert_upgrades/3` after
    installing at `version`, to insert data.
  * `:verify` — `fn version, ctx -> ... end`, run by `assert_upgrades/3`
    after upgrading from `version`, to check that data.

# `assert_baseline_matches`

A fresh install through the baseline matches running every version.

# `assert_preserves_host_changes`

After each version, a host adds a column and an index to every library
table; they must survive every later version.

# `assert_rerunnable`

Each version runs again after failing halfway: its tracking is reset to the
previous version and it runs a second time.

# `assert_round_trip`

Every version goes up, down and up again, with matching schemas.

# `assert_upgrades`

An install at each version upgrades to the latest schema.

# `down`

Runs `migrations.down(opts)` inside a real Ecto migration.

# `reset!`

Empties the prefix (or the SQLite database).

# `run`

Runs `fun` as the `up/0` of a one-off Ecto migration.

# `run_suite`

Runs every check. See the module documentation.

# `schema`

The comparable schema of the prefix, without tracking tables.

# `up`

Runs `migrations.up(opts)` inside a real Ecto migration, outside a
transaction when the versions need it.

# `write_snapshot!`

Writes the schema of a fresh install at the latest version to the
library's `priv/phoenix_mountable`, for `verify/1` at runtime.

---

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