Skip to main content

Module migration

Module migration 

Source
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 VARCHAR(255) PRIMARY KEY, applied_at VARCHAR(64)) if absent (VARCHAR: MySQL can’t key a TEXT column; tables made as TEXT by earlier releases keep working). 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§

MigrationStatus
Status of a single migration file.

Functions§

migration_status
Return status (applied / pending) for each SQL file in dir. Called by DbPool::migration_status.
rollback
Roll back the last n applied migrations, most recently applied first. Called by DbPool::rollback.
rollback_last
Roll back the most recently applied migration in dir. Called by DbPool::rollback_last.
run_migrations
Run pending migrations from SQL files in dir. Called by DbPool::migrate.
run_seeds
Run every *.sql file in dir, in order, each in one transaction. Called by DbPool::seed.