pub struct Step { /* private fields */ }Expand description
Implementations§
Source§impl Step
impl Step
Sourcepub fn new(
name: impl Into<String>,
up: impl Fn(Dialect) -> Vec<String> + Send + Sync + 'static,
down: impl Fn(Dialect) -> Down + Send + Sync + 'static,
) -> Self
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.
Sourcepub fn raw(name: impl Into<String>, up: Vec<String>, down: Vec<String>) -> Self
pub fn raw(name: impl Into<String>, up: Vec<String>, down: Vec<String>) -> Self
A step running fixed SQL either way, whatever the dialect.
Sourcepub fn raw_irreversible(
name: impl Into<String>,
up: Vec<String>,
reason: impl Into<String>,
) -> Self
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.
Sourcepub fn create_table<E: Entity>(name: impl Into<String>) -> Self
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.
Sourcepub fn create(
name: impl Into<String>,
table: impl Into<String>,
build: impl FnOnce(&mut Blueprint),
) -> Self
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.
Sourcepub fn table(
name: impl Into<String>,
table: impl Into<String>,
build: impl FnOnce(&mut TableChanges),
) -> Self
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.