Struct barrel::migration::Migration

source ·
pub struct Migration { /* private fields */ }
Expand description

Represents a schema migration on a database

Implementations§

source§

impl Migration

source

pub fn new() -> Migration

source

pub fn schema<S: Into<String>>(self, schema: S) -> Migration

Specify a database schema name for this migration

source

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

source

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!

source

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.

source

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)

source

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

source

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

source

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

source

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

source

pub fn rename_table<S: Into<String>>(&mut self, old: S, new: S)

Rename a table

source

pub fn drop_table<S: Into<String>>(&mut self, name: S)

Drop an existing table

source

pub fn drop_table_if_exists<S: Into<String>>(&mut self, name: S)

Only drop a table if it exists

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.