pub struct Migration { /* private fields */ }Expand description
An ordered set of schema operations under one migration name — the unit
the Migrator records in _orm_migrations and
applies once.
Build it fluently; it renders to dialect SQL only when applied (or via
render for inspection/tests). Each builder method appends
one operation, and operations apply in call order.
Implementations§
Source§impl Migration
impl Migration
Sourcepub fn new(name: &'static str) -> Self
pub fn new(name: &'static str) -> Self
A new, empty migration identified by name (the ordering + dedupe key).
Sourcepub fn create_table<E: Entity + 'static>(self) -> Self
pub fn create_table<E: Entity + 'static>(self) -> Self
Create E’s table and its derived indexes, idempotently
(CREATE TABLE IF NOT EXISTS) — the same DDL
Migrator::create_table
emits, available here so a create and subsequent alters can share one
migration step.
Sourcepub fn statement<S>(self, stmt: S) -> Selfwhere
S: SchemaStatementBuilder + 'static,
pub fn statement<S>(self, stmt: S) -> Selfwhere
S: SchemaStatementBuilder + 'static,
Append an explicit sea_query schema statement — a CREATE TABLE,
CREATE INDEX, ALTER TABLE, … built directly with the re-exported
sea_query module. The bridge for schemas authored as
sea-query statements rather than through the typed ops above (or derived
from an Entity); rendered for the executor’s dialect at apply time,
so one definition still runs on every backend.
Sourcepub fn add_column(self, table: &str, column: Column) -> Self
pub fn add_column(self, table: &str, column: Column) -> Self
Add a column to table. See Column for nullability/default rules.
Sourcepub fn drop_column(self, table: &str, column: &str) -> Self
pub fn drop_column(self, table: &str, column: &str) -> Self
Drop column from table (SQLite ≥ 3.35 / modern D1 support this).
Sourcepub fn rename_column(self, table: &str, from: &str, to: &str) -> Self
pub fn rename_column(self, table: &str, from: &str, to: &str) -> Self
Rename from → to on table.
Sourcepub fn rename_table(self, from: &str, to: &str) -> Self
pub fn rename_table(self, from: &str, to: &str) -> Self
Rename a table.
Sourcepub fn drop_table(self, table: &str) -> Self
pub fn drop_table(self, table: &str) -> Self
Drop a table if it exists.
Sourcepub fn create_index<'c, I>(self, name: &str, table: &str, columns: I) -> Selfwhere
I: IntoIterator<Item = &'c str>,
pub fn create_index<'c, I>(self, name: &str, table: &str, columns: I) -> Selfwhere
I: IntoIterator<Item = &'c str>,
Create a non-unique secondary index (IF NOT EXISTS).
Sourcepub fn create_unique_index<'c, I>(
self,
name: &str,
table: &str,
columns: I,
) -> Selfwhere
I: IntoIterator<Item = &'c str>,
pub fn create_unique_index<'c, I>(
self,
name: &str,
table: &str,
columns: I,
) -> Selfwhere
I: IntoIterator<Item = &'c str>,
Create a UNIQUE index (IF NOT EXISTS).
Sourcepub fn drop_index(self, name: &str, table: &str) -> Self
pub fn drop_index(self, name: &str, table: &str) -> Self
Drop a named index off table.
Sourcepub fn raw(self, dialect: Dialect, sql: impl Into<String>) -> Self
pub fn raw(self, dialect: Dialect, sql: impl Into<String>) -> Self
Raw SQL emitted only for dialect — the escape hatch for anything
the portable ops can’t express (e.g. a MySQL MODIFY COLUMN, a Postgres
ALTER COLUMN … TYPE). Ignored on every other dialect, so a migration
can carry per-dialect variants of the same change side by side.