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
sourceimpl<DB: Database> Migration<DB>
impl<DB: Database> Migration<DB>
sourcepub fn new(
name: impl Into<Cow<'static, str>>,
up: impl for<'future> Fn(&'future mut Transaction<'_, DB>) -> LocalBoxFuture<'future, Result<(), MigrationError>> + 'static
) -> Self
pub fn new(
name: impl Into<Cow<'static, str>>,
up: impl for<'future> Fn(&'future mut Transaction<'_, DB>) -> LocalBoxFuture<'future, Result<(), MigrationError>> + 'static
) -> Self
Create a new migration with the given name and migration function.
sourcepub fn reversible(
self,
down: impl for<'future> Fn(&'future mut Transaction<'_, DB>) -> LocalBoxFuture<'future, Result<(), MigrationError>> + 'static
) -> Self
pub fn reversible(
self,
down: impl for<'future> Fn(&'future mut Transaction<'_, DB>) -> LocalBoxFuture<'future, Result<(), MigrationError>> + 'static
) -> Self
Set a down migration function.
sourcepub fn revertible(
self,
down: impl for<'future> Fn(&'future mut Transaction<'_, DB>) -> LocalBoxFuture<'future, Result<(), MigrationError>> + 'static
) -> Self
pub fn revertible(
self,
down: impl for<'future> Fn(&'future mut Transaction<'_, DB>) -> LocalBoxFuture<'future, Result<(), MigrationError>> + 'static
) -> Self
Same as Migration::reversible
sourcepub fn with_checksum(self, checksum: impl Into<Cow<'static, [u8]>>) -> Self
pub fn with_checksum(self, checksum: impl Into<Cow<'static, [u8]>>) -> Self
Set a checksum for the migration.
A checksum is only useful for migrations that come from external sources.
sourcepub fn checksum(&self) -> &[u8]ⓘNotable traits for &'_ mut [u8]impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
pub fn checksum(&self) -> &[u8]ⓘNotable traits for &'_ mut [u8]impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
Get a reference to the migration’s checksum.
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
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more