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")
endrun_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 forup/1, such asprimary_key: :binary_id.:seed—fn version, ctx -> ... end, run byassert_upgrades/3after installing atversion, to insert data.:verify—fn version, ctx -> ... end, run byassert_upgrades/3after upgrading fromversion, to check that data.
Summary
Functions
A fresh install through the baseline matches running every version.
After each version, a host adds a column and an index to every library table; they must survive every later version.
Each version runs again after failing halfway: its tracking is reset to the previous version and it runs a second time.
Every version goes up, down and up again, with matching schemas.
An install at each version upgrades to the latest schema.
Runs migrations.down(opts) inside a real Ecto migration.
Empties the prefix (or the SQLite database).
Runs fun as the up/0 of a one-off Ecto migration.
Runs every check. See the module documentation.
The comparable schema of the prefix, without tracking tables.
Runs migrations.up(opts) inside a real Ecto migration, outside a
transaction when the versions need it.
Writes the schema of a fresh install at the latest version to the
library's priv/phoenix_mountable, for verify/1 at runtime.
Functions
A fresh install through the baseline matches running every version.
After each version, a host adds a column and an index to every library table; they must survive every later version.
Each version runs again after failing halfway: its tracking is reset to the previous version and it runs a second time.
Every version goes up, down and up again, with matching schemas.
An install at each version upgrades to the latest schema.
Runs migrations.down(opts) inside a real Ecto migration.
Empties the prefix (or the SQLite database).
Runs fun as the up/0 of a one-off Ecto migration.
Runs every check. See the module documentation.
The comparable schema of the prefix, without tracking tables.
Runs migrations.up(opts) inside a real Ecto migration, outside a
transaction when the versions need it.
Writes the schema of a fresh install at the latest version to the
library's priv/phoenix_mountable, for verify/1 at runtime.