Expand description
Portable, reversible migrations.
A migration is a Rust unit implementing Migration: a stable name, an
up, and an optional down (absent means the migration is irreversible).
DDL is written with the sea-query schema builder through the Schema
handle, which renders for whichever backend the deployment runs on, so one
migration serves Postgres, MySQL, and SQLite. Raw SQL stays available as an
escape hatch, and SqlMigration wraps a pure-SQL up/down pair.
A module exposes an ordered MigrationSet (its version history). The
runner applies pending migrations (run) and reverses them (rollback,
reset), tracking what is applied by (module_id, name) in a single
laterite_migrations table. Queries run over sqlx::Any, so the same runner
drives every supported backend.
Structs§
- Migration
Set - A module’s ordered migrations: the version history for
module_id. - Schema
- The handle a migration uses to change the schema. Renders
sea-querystatements for the running backend, with a raw-SQL escape hatch. - SqlMigration
- A migration whose up and down are raw SQL strings.
downis optional; its absence makes the migration irreversible.
Enums§
- DbBackend
- The database backend a deployment runs on. Selects the
sea-queryrenderer so migrations and the runner emit SQL the target understands.
Constants§
- KEY_LEN
- The length of a
key_col, generous enough for UUIDs, codes, usernames, emails, and token hashes while staying within MySQL’s index-length limit.
Traits§
- Migration
- One migration: a stable name, an
up, and an optionaldown.
Functions§
- applied
- The names applied for a module, in application order.
- bool_
col - A portable boolean column, stored as a 0/1 integer. Use this in a migration
instead of
ColumnDef::new(name).boolean():sqlx::Anycannot decode a SQLitebooleancolumn, so integer is the representation that works on every backend. Bind and read the value as a normalboolthrough the query layer (seecrate::query). Chain.not_null(),.default(0), and so on as usual. - key_col
- A portable key column: a bounded
varcharrather thantext. Use this in a migration for any column that participates in a key, index, or foreign key (ids, codes, tokens, and columns named in anIndex): MySQL cannot index atextcolumn without a prefix length, so a plaintextid or unique column fails there. A bounded string keys cleanly on every backend. It holds the same UTF-8 strings atextcolumn would, so application code is unchanged. Chain.not_null(),.primary_key(),.unique_key(), and so on as usual. - reset
- Reverses every applied migration of one module.
- rollback
- Reverses the last
stepsapplied migrations of one module, most recent first. An irreversible migration in the way stops the rollback. - run
- Applies every pending migration across the given sets, in listed order and, within a set, in declared order. Each migration runs in its own transaction.