Skip to main content

Migration

Struct Migration 

Source
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

Source

pub fn new(name: &'static str) -> Self

A new, empty migration identified by name (the ordering + dedupe key).

Source

pub fn name(&self) -> &'static str

This migration’s name.

Source

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.

Source

pub fn statement<S>(self, stmt: S) -> Self
where 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.

Source

pub fn add_column(self, table: &str, column: Column) -> Self

Add a column to table. See Column for nullability/default rules.

Source

pub fn drop_column(self, table: &str, column: &str) -> Self

Drop column from table (SQLite ≥ 3.35 / modern D1 support this).

Source

pub fn rename_column(self, table: &str, from: &str, to: &str) -> Self

Rename from → to on table.

Source

pub fn rename_table(self, from: &str, to: &str) -> Self

Rename a table.

Source

pub fn drop_table(self, table: &str) -> Self

Drop a table if it exists.

Source

pub fn create_index<'c, I>(self, name: &str, table: &str, columns: I) -> Self
where I: IntoIterator<Item = &'c str>,

Create a non-unique secondary index (IF NOT EXISTS).

Source

pub fn create_unique_index<'c, I>( self, name: &str, table: &str, columns: I, ) -> Self
where I: IntoIterator<Item = &'c str>,

Create a UNIQUE index (IF NOT EXISTS).

Source

pub fn drop_index(self, name: &str, table: &str) -> Self

Drop a named index off table.

Source

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.

Source

pub fn raw_all(self, sql: impl Into<String>) -> Self

Raw SQL emitted for every dialect — only sound for statements that are byte-identical across backends. Prefer the typed ops or raw; this is the last resort.

Source

pub fn render(&self, dialect: Dialect) -> Vec<String>

Every statement this migration runs on dialect, in apply order — for inspection, tests, or dumping a .sql file.

Trait Implementations§

Source§

impl<X: Executor> Migration<X> for Migration

Source§

fn name(&self) -> &'static str

Source§

fn up<'a>(&'a self, db: &'a X) -> StepFuture<'a>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.