Struct sqlx_migrate::Migration

source ·
pub struct Migration<DB: Database> { /* private fields */ }
Expand description

A single migration that uses a given [sqlx::Transaction] to do the up (migrate) and down (revert) migrations.

Example

use sqlx_migrate::Migration;
use sqlx::{Executor, Postgres};

let migration = Migration::<Postgres>::new("initial migration", |tx| {
    Box::pin(async move {
        tx.execute("CREATE TABLE example ();").await?;
        Ok(())
    })
})
// Low-effort (optional) checksum.
.with_checksum(b"CREATE TABLE example ();".as_slice())
.reversible(|tx| {
    Box::pin(async move {
        tx.execute("DROP TABLE example;");
        Ok(())
    })
});

Implementations§

source§

impl<DB: Database> Migration<DB>

source

pub fn new( name: impl Into<Cow<'static, str>>, up: impl Fn(&mut MigrationContext<DB>) -> LocalBoxFuture<'_, Result<(), MigrationError>> + 'static ) -> Self

Create a new migration with the given name and migration function.

source

pub fn reversible( self, down: impl Fn(&mut MigrationContext<DB>) -> LocalBoxFuture<'_, Result<(), MigrationError>> + 'static ) -> Self

Set a down migration function.

source

pub fn revertible( self, down: impl Fn(&mut MigrationContext<DB>) -> LocalBoxFuture<'_, Result<(), MigrationError>> + 'static ) -> Self

source

pub fn name(&self) -> &str

Get the migration’s name.

source

pub fn is_reversible(&self) -> bool

Whether the migration is reversible or not.

source

pub fn is_revertible(&self) -> bool

Whether the migration is reversible or not.

Trait Implementations§

source§

impl<DB: Database> PartialEq<Migration<DB>> for Migration<DB>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<DB: Database> Eq for Migration<DB>

Auto Trait Implementations§

§

impl<DB> !RefUnwindSafe for Migration<DB>

§

impl<DB> !Send for Migration<DB>

§

impl<DB> !Sync for Migration<DB>

§

impl<DB> Unpin for Migration<DB>

§

impl<DB> !UnwindSafe for Migration<DB>

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
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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 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> Same<T> for T

§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

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