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>
impl<DB: Database> Migration<DB>
Sourcepub fn new(
name: impl Into<Cow<'static, str>>,
up: impl Fn(&mut MigrationContext<DB>) -> LocalBoxFuture<'_, Result<(), MigrationError>> + 'static,
) -> Self
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.
Sourcepub fn reversible(
self,
down: impl Fn(&mut MigrationContext<DB>) -> LocalBoxFuture<'_, Result<(), MigrationError>> + 'static,
) -> Self
pub fn reversible( self, down: impl Fn(&mut MigrationContext<DB>) -> LocalBoxFuture<'_, Result<(), MigrationError>> + 'static, ) -> Self
Set a down migration function.
Sourcepub fn revertible(
self,
down: impl Fn(&mut MigrationContext<DB>) -> LocalBoxFuture<'_, Result<(), MigrationError>> + 'static,
) -> Self
pub fn revertible( self, down: impl Fn(&mut MigrationContext<DB>) -> LocalBoxFuture<'_, Result<(), MigrationError>> + 'static, ) -> Self
Same as Migration::reversible
Sourcepub fn is_reversible(&self) -> bool
pub fn is_reversible(&self) -> bool
Whether the migration is reversible or not.
Sourcepub fn is_revertible(&self) -> bool
pub fn is_revertible(&self) -> bool
Whether the migration is reversible or not.
Trait Implementations§
Auto Trait Implementations§
impl<DB> Freeze for Migration<DB>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more