lode/migrator
Runs migrations against a repo and tracks applied versions in a
schema_migrations table — the Ecto.Migrator equivalent. Each migration
runs in its own transaction, so a failed migration rolls back cleanly.
Call the library functions directly, or use run to build a CLI:
migrator.migrate(repo, all_migrations()) migrator.rollback(repo, all_migrations(), steps: 1) migrator.status(repo, all_migrations())
run parses migrate / rollback [n] / status from argv-style args and
prints the result — wire it up in your own main:
pub fn main() { let repo = repo.new(postgres.new(connect())) let assert Ok(_) = migrator.run(repo, all_migrations(), argv.load().arguments) }
Requires an adapter that supports execute_ddl/query_sql (the Postgres
and SQLite adapters; the in-memory adapter does not). The DDL dialect is
inferred from the adapter’s engine tag.
Types
Whether a migration has been applied.
pub type MigrationStatus {
MigrationStatus(version: Int, applied: Bool)
}
Constructors
-
MigrationStatus(version: Int, applied: Bool)
Values
pub fn migrate(
repo r: repo.Repo,
migrations migrations: List(migration.Migration),
) -> Result(List(Int), error.LodeError)
Apply all pending migrations in ascending version order. Returns the versions that were applied.
pub fn rollback(
repo r: repo.Repo,
migrations migrations: List(migration.Migration),
steps steps: Int,
) -> Result(List(Int), error.LodeError)
Roll back the most recently applied migrations, newest first. Returns the versions that were rolled back.
pub fn run(
repo r: repo.Repo,
migrations migrations: List(migration.Migration),
args args: List(String),
) -> Result(Nil, error.LodeError)
Dispatch an argv-style command (migrate, rollback [n], status) against
the repo, printing the outcome. Returns Error on an unknown command (so a
let assert Ok(_) in your main exits non-zero) or on a migration failure.
pub fn status(
repo r: repo.Repo,
migrations migrations: List(migration.Migration),
) -> Result(List(MigrationStatus), error.LodeError)
The applied/pending status of every given migration, ascending.