pub struct Migration { /* private fields */ }
Expand description
Represents a schema migration on a database
Implementations§
source§impl Migration
impl Migration
pub fn new() -> Migration
sourcepub fn schema<S: Into<String>>(self, schema: S) -> Migration
pub fn schema<S: Into<String>>(self, schema: S) -> Migration
Specify a database schema name for this migration
sourcepub fn make<T: SqlGenerator>(&self) -> String
pub fn make<T: SqlGenerator>(&self) -> String
Creates the SQL for this migration for a specific backend
This function copies state and does not touch the original
migration layout. This allows you to call revert
later on
in the process to auto-infer the down-behaviour
sourcepub fn make_from(&self, variant: SqlVariant) -> String
pub fn make_from(&self, variant: SqlVariant) -> String
The same as make
but making a run-time check for sql variant
The SqlVariant
type is populated based on the backends
that are being selected at compile-time.
This function panics if the provided variant is empty!
sourcepub fn inject_custom<S: Into<String>>(&mut self, sql: S)
pub fn inject_custom<S: Into<String>>(&mut self, sql: S)
Inject a line of custom SQL into the top-level migration scope
This is a bypass to the barrel typesystem, in case there is something your database supports that barrel doesn’t, or if there is an issue with the way that barrel represents types. It does however mean that the SQL provided needs to be specific for one database, meaning that future migrations might become cumbersome.
sourcepub fn revert<T: SqlGenerator>(&self) -> String
pub fn revert<T: SqlGenerator>(&self) -> String
Automatically infer the down
step of this migration
Will thrown an error if behaviour is ambiguous or not
possible to infer (e.g. revert a drop_table
)
sourcepub fn execute<S: SqlGenerator, T: SqlRunner>(&self, runner: &mut T)
pub fn execute<S: SqlGenerator, T: SqlRunner>(&self, runner: &mut T)
Pass a reference to a migration toolkit runner which will automatically generate and execute
sourcepub fn create_table<S: Into<String>, F>(
&mut self,
name: S,
cb: F
) -> &mut TableMetawhere
F: Fn(&mut Table) + 'static,
pub fn create_table<S: Into<String>, F>( &mut self, name: S, cb: F ) -> &mut TableMetawhere F: Fn(&mut Table) + 'static,
Create a new table with a specific name
sourcepub fn create_table_if_not_exists<S: Into<String>, F>(
&mut self,
name: S,
cb: F
) -> &mut TableMetawhere
F: Fn(&mut Table) + 'static,
pub fn create_table_if_not_exists<S: Into<String>, F>( &mut self, name: S, cb: F ) -> &mut TableMetawhere F: Fn(&mut Table) + 'static,
Create a new table only if it doesn’t exist yet
sourcepub fn change_table<S: Into<String>, F>(&mut self, name: S, cb: F)where
F: Fn(&mut Table) + 'static,
pub fn change_table<S: Into<String>, F>(&mut self, name: S, cb: F)where F: Fn(&mut Table) + 'static,
Change fields on an existing table
sourcepub fn rename_table<S: Into<String>>(&mut self, old: S, new: S)
pub fn rename_table<S: Into<String>>(&mut self, old: S, new: S)
Rename a table
sourcepub fn drop_table<S: Into<String>>(&mut self, name: S)
pub fn drop_table<S: Into<String>>(&mut self, name: S)
Drop an existing table
sourcepub fn drop_table_if_exists<S: Into<String>>(&mut self, name: S)
pub fn drop_table_if_exists<S: Into<String>>(&mut self, name: S)
Only drop a table if it exists