pub struct Migrator {
pub migrations: Cow<'static, [Migration]>,
pub ignore_missing: bool,
}
Fields§
§migrations: Cow<'static, [Migration]>
§ignore_missing: bool
Implementations§
Source§impl Migrator
impl Migrator
Sourcepub async fn new<'s, S>(source: S) -> Result<Self, MigrateError>where
S: MigrationSource<'s>,
pub async fn new<'s, S>(source: S) -> Result<Self, MigrateError>where
S: MigrationSource<'s>,
Creates a new instance with the given source.
§Examples
use std::path::Path;
// Read migrations from a local folder: ./migrations
let m = Migrator::new(Path::new("./migrations")).await?;
See MigrationSource for details on structure of the ./migrations
directory.
Sourcepub fn set_ignore_missing(&mut self, ignore_missing: bool) -> &Self
pub fn set_ignore_missing(&mut self, ignore_missing: bool) -> &Self
Specify should ignore applied migrations that missing in the resolved migrations.
Sourcepub async fn run<'a, A>(&self, migrator: A) -> Result<(), MigrateError>
pub async fn run<'a, A>(&self, migrator: A) -> Result<(), MigrateError>
Run any pending migrations against the database; and, validate previously applied migrations against the current migration source to detect accidental changes in previously-applied migrations.
§Examples
let m = Migrator::new(std::path::Path::new("./migrations")).await?;
let pool = sqlx_core::sqlite::SqlitePoolOptions::new().connect("sqlite::memory:").await?;
m.run(&pool).await
Sourcepub async fn undo<'a, A>(
&self,
migrator: A,
target: i64,
) -> Result<(), MigrateError>
pub async fn undo<'a, A>( &self, migrator: A, target: i64, ) -> Result<(), MigrateError>
Run down migrations against the database until a specific version.
§Examples
let m = Migrator::new(std::path::Path::new("./migrations")).await?;
let pool = sqlx_core::sqlite::SqlitePoolOptions::new().connect("sqlite::memory:").await?;
m.undo(&pool, 4).await
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Migrator
impl RefUnwindSafe for Migrator
impl Send for Migrator
impl Sync for Migrator
impl Unpin for Migrator
impl UnwindSafe for Migrator
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<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