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(MigrationContext<'future, DB>) -> LocalBoxFuture<'future, Result<(), MigrationError>> + 'static
) -> Self
pub fn new(
name: impl Into<Cow<'static, str>>,
up: impl for<'future> Fn(MigrationContext<'future, 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(MigrationContext<'future, DB>) -> LocalBoxFuture<'future, Result<(), MigrationError>> + 'static
) -> Self
pub fn reversible(
self,
down: impl for<'future> Fn(MigrationContext<'future, DB>) -> LocalBoxFuture<'future, Result<(), MigrationError>> + 'static
) -> Self
Set a down migration function.
sourcepub fn revertible(
self,
down: impl for<'future> Fn(MigrationContext<'future, DB>) -> LocalBoxFuture<'future, Result<(), MigrationError>> + 'static
) -> Self
pub fn revertible(
self,
down: impl for<'future> Fn(MigrationContext<'future, DB>) -> LocalBoxFuture<'future, 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
sourceimpl<DB: Database> PartialEq<Migration<DB>> for Migration<DB>
impl<DB: Database> PartialEq<Migration<DB>> for Migration<DB>
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 Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
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 Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
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.