Struct sqlx_core::migrate::Migrator

source ·
pub struct Migrator {
    pub migrations: Cow<'static, [Migration]>,
    pub ignore_missing: bool,
}

Fields§

§migrations: Cow<'static, [Migration]>§ignore_missing: bool

Implementations§

source§

impl Migrator

source

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.

source

pub fn set_ignore_missing(&mut self, ignore_missing: bool) -> &Self

Specify should ignore applied migrations that missing in the resolved migrations.

source

pub fn iter(&self) -> Iter<'_, Migration>

Get an iterator over all known migrations.

source

pub async fn run<'a, A>(&self, migrator: A) -> Result<(), MigrateError>
where A: Acquire<'a>, <A::Connection as Deref>::Target: Migrate,

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
source

pub async fn undo<'a, A>( &self, migrator: A, target: i64 ) -> Result<(), MigrateError>
where A: Acquire<'a>, <A::Connection as Deref>::Target: Migrate,

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§

source§

impl Debug for Migrator

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where 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 for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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.
source§

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

source§

fn vzip(self) -> V