pub struct Validator {
pub migrations: Cow<'static, [Migration]>,
pub ignore_missing: bool,
pub locking: bool,
}
Expand description
Validate previously applied migrations against the migration source.
Depending on the migration source this can be used to check if all migrations
for the current version of the application have been applied.
Use Validator::from_migrator
to use the migrations available during compilation.
§Examples
// Use migrations that were in a local folder during build: ./tests/migrations-1
let v = Validator::from_migrator(sqlx::migrate!("./tests/migrations-1"));
// Create a connection pool
let pool = sqlx_core::sqlite::SqlitePoolOptions::new().connect("sqlite::memory:").await?;
let mut conn = pool.acquire().await?;
// Validate the migrations
v.validate(&mut *conn).await?;
Fields§
§migrations: Cow<'static, [Migration]>
§ignore_missing: bool
§locking: bool
Implementations§
Source§impl Validator
impl Validator
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. Please note that the source
is resolved at runtime and not at compile time.
You can use Validator::from<sqlx::Migrator>
and the sqlx::migrate!
macro
to embed the migrations into the binary during compile time.
§Examples
use std::path::Path;
// Read migrations from a local folder: ./tests/migrations-1
let v = Validator::new(Path::new("./tests/migrations-1")).await?;
// Create a connection pool
let pool = sqlx::PgPool::connect("postgres://postgres:postgres@localhost:5432/postgres").await?;
let mut conn = pool.acquire().await?;
// Validate the migrations
v.validate(&mut *conn).await?;
See MigrationSource for details on structure of the ./tests/migrations-1
directory.
Sourcepub fn from_migrator(migrator: Migrator) -> Self
pub fn from_migrator(migrator: Migrator) -> Self
Creates a new instance with the migrations from the given migrator.
You can combine this with the sqlx::migrate!
macro
to embed the migrations into the binary during compile time.
§Examples
// Use migrations that were in a local folder during build: ./tests/migrations-1
let v = Validator::from_migrator(sqlx::migrate!("./tests/migrations-1"));
// Create a connection pool
let pool = sqlx::PgPool::connect("postgres://postgres:postgres@localhost:5432/postgres").await?;
let mut conn = pool.acquire().await?;
// Validate the migrations
v.validate(&mut *conn).await?;
pub async fn validate<'c, C>(&self, conn: &mut C) -> Result<(), ValidateError>where
C: Migrate,
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Validator
impl RefUnwindSafe for Validator
impl Send for Validator
impl Sync for Validator
impl Unpin for Validator
impl UnwindSafe for Validator
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
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>
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>
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