Skip to main content

Step

Struct Step 

Source
pub struct Step { /* private fields */ }
Expand description

A Migration built from closures — what the builder methods produce.

Implement Migration directly when a migration wants a name of its own and a place to live; use Step when it is two lists of statements.

Implementations§

Source§

impl Step

Source

pub fn new( name: impl Into<String>, up: impl Fn(Dialect) -> Vec<String> + Send + Sync + 'static, down: impl Fn(Dialect) -> Down + Send + Sync + 'static, ) -> Self

A step from an up and a down renderer.

Source

pub fn raw(name: impl Into<String>, up: Vec<String>, down: Vec<String>) -> Self

A step running fixed SQL either way, whatever the dialect.

Source

pub fn raw_irreversible( name: impl Into<String>, up: Vec<String>, reason: impl Into<String>, ) -> Self

A step that applies fixed SQL and cannot be undone, with the reason.

Source

pub fn create_table<E: Entity>(name: impl Into<String>) -> Self

A step creating E’s table and its indexes, from the derived metadata.

Its down drops the table, which is the honest inverse — and also why rolling back a create_table in production destroys data. That is a property of the operation, not of this implementation.

Source

pub fn create( name: impl Into<String>, table: impl Into<String>, build: impl FnOnce(&mut Blueprint), ) -> Self

A step creating table from a Blueprint — Laravel’s Schema::create.

For a table no model describes: a pivot, a join table, something a third-party tool reads. The description is written once and lowered to whichever engine the executor reports, so there is no per-dialect SQL to keep in step.

ⓘ
Step::create("0007_create_post_tag", "post_tag", |table| {
    table.foreign_id("post_id").constrained_on("posts").cascade_on_delete();
    table.foreign_id("tag_id").constrained_on("tags").cascade_on_delete();
    table.primary(["post_id", "tag_id"]);
})

Its down drops the table — which is the honest inverse, and also why rolling one back in production destroys data.

Source

pub fn table( name: impl Into<String>, table: impl Into<String>, build: impl FnOnce(&mut TableChanges), ) -> Self

A step changing a table that already exists — Laravel’s Schema::table.

ⓘ
Step::table("0008_posts_add_subtitle", "posts", |table| {
    table.string("subtitle").nullable();
    table.index(["author_id", "published"]);
})

The down is derived from what changed, so it cannot drift from the up the way a hand-written one does. Where a change genuinely cannot be undone — a dropped column, a raw statement with no reverse — the step reports itself irreversible and says which change made it so.

Source

pub fn drop_table(name: impl Into<String>, table: impl Into<String>) -> Self

A step dropping a table.

Irreversible, and deliberately so: nothing here knows the shape of what it dropped, and a down that recreated an empty table would report success having restored nothing.

Source

pub fn rename_table( name: impl Into<String>, from: impl Into<String>, to: impl Into<String>, ) -> Self

A step renaming a table. Reverses by renaming it back.

ALTER TABLE … RENAME TO on SQLite and Postgres, RENAME TABLE on MySQL — one of the several places the engines simply disagree.

Trait Implementations§

Source§

impl Debug for Step

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Migration for Step

Source§

fn name(&self) -> &str

The name recorded in the ledger. Read more
Source§

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

The statements that apply this migration to dialect. Read more
Source§

fn down(&self, dialect: Dialect) -> Down

How to undo it.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Step

§

impl !UnwindSafe for Step

§

impl Freeze for Step

§

impl Send for Step

§

impl Sync for Step

§

impl Unpin for Step

§

impl UnsafeUnpin for Step

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> Event for T
where T: Send + Sync + 'static,

Source§

fn event_name() -> &'static str
where Self: Sized,

A human-readable name, used by wildcard listeners and log output. Always the Rust type path; see the trait docs.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more