Available on crate features
model-mysql or model-postgres or model-sqlite only.Expand description
Async migration runner.
Reads *.sql files from a directory in lexicographic order. Creates
_schema_migrations(version TEXT PRIMARY KEY, applied_at TEXT) if absent.
Runs each unapplied file inside a transaction.
Rollback: an up file NNNN_name.sql may have a companion down file
NNNN_name.down.sql in the same directory. rollback_last and
rollback undo the most recently applied migration(s) — determined by
version order, the same invariant run_migrations relies on to apply
files in order — by running the down file’s SQL and deleting the row
from _schema_migrations, both inside one transaction.
Structs§
- Migration
Status - Status of a single migration file.
Functions§
- migration_
status - Return status (applied / pending) for each SQL file in
dir. Called byDbPool::migration_status. - rollback
- Roll back the last
napplied migrations, most recently applied first. Called byDbPool::rollback. - rollback_
last - Roll back the most recently applied migration in
dir. Called byDbPool::rollback_last. - run_
migrations - Run pending migrations from SQL files in
dir. Called byDbPool::migrate.