Skip to main content

Module migration

Module migration 

Source
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§

MigrationSet
A module’s ordered migrations: the version history for module_id.
Schema
The handle a migration uses to change the schema. Renders sea-query statements for the running backend, with a raw-SQL escape hatch.
SqlMigration
A migration whose up and down are raw SQL strings. down is optional; its absence makes the migration irreversible.

Enums§

DbBackend
The database backend a deployment runs on. Selects the sea-query renderer 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 optional down.

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::Any cannot decode a SQLite boolean column, so integer is the representation that works on every backend. Bind and read the value as a normal bool through the query layer (see crate::query). Chain .not_null(), .default(0), and so on as usual.
key_col
A portable key column: a bounded varchar rather than text. Use this in a migration for any column that participates in a key, index, or foreign key (ids, codes, tokens, and columns named in an Index): MySQL cannot index a text column without a prefix length, so a plain text id or unique column fails there. A bounded string keys cleanly on every backend. It holds the same UTF-8 strings a text column 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 steps applied 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.