Expand description
migratio is a library for managing database migrations.
Core concepts:
- Live DB Connections:
migratiosupplies migration definitions with a live connection to the database, allowing more expressive migration logic than just preparing SQL statements. - Code-First:
migratiois a code-first library, making embedding it in your application easier than other CLI-first libraries.
§Motivation
§Using a Live Database Connection
Most Rust-based migration solutions focus only on using SQL to define migration logic. Even the ones that say they support writing migrations in Rust use Rust to simply construct SQL instructions, like Refinery.
Taking a hint from Alembic, this library provides the user with a live connection to the database with which to define their migrations. With a live connection, a migration can query the data, transform it in Rust, and write it back. Migrations defined as pure SQL statements can only accomplish this with the toolkit provided by SQL, which is much more limited.
Note: SeaORM allows this, but migratio aims to provide an alternative for developers that don’t want to adopt a full ORM solution.
§Code-first approach
A central use case for migratio is embedding migration logic within an application, usually in the startup procedure.
This way, when the application updates, the next time it starts the database will automatically be migrated to the latest version without any manual intervention.
§Benefits
- Easy adoption from other migration tools or no migration tool.
- Robust error handling and rollback support (when available).
- Preview / dry-run support.
- Migration history querying.
- Observability hooks.
- Tracing integration = available with the
tracingfeature flag. - Testing utilities - available with the
testingfeature flag.
§Database support
SQLite- available with thesqlitefeature flag.MySQL- available with themysqlfeature flag.PostgreSQL- available with thepostgresfeature flag.
Modules§
- mysql
mysql - MySQL migration support
- postgres
postgres - PostgreSQL migration support
- sqlite
sqlite - SQLite migration support
- testing
testing - Testing utilities for migration development
Macros§
- sql_
migration - Define a simple SQL-only migration.
Structs§
- Applied
Migration - Represents a migration that has been applied to the database.
- Migration
Failure - Represents a failure during a migration.
- Migration
Report - A report of actions performed during a migration.
Enums§
- Error
- Error type for the migratio crate.
- Migration
Type - Represents the type of a migration entry.
- Precondition
- Represents the result of a migration precondition check.
Traits§
- Migration
- A trait that must be implemented to define a migration.
The
versionvalue must be unique among all migrations supplied to a migrator, and greater than 0. Thenameanddescriptionmethods are optional, and only aid in debugging / observability.