Expand description

With sqlx and its sqlx::migrate! macro it is possible to create migrations and apply them to a database. When starting an application it is important to validate that the database is in the correct state. This crate provides a way to validate that the applied migrations match the desired migrations. In combination with the sqlx::migrate! macro it is possible to validate that the database schema matches the migrations present in the source code at the time of compilation.

While this does not ensure full compatibility between the database and the application it can help to detect issues early.


use sqlx_migrate_validate::{Validate, Validator};

async fn main() -> Result<(), anyhow::Error> {
    let pool = sqlx::SqlitePool::connect("sqlite::memory:").await?;
    let mut conn = pool.acquire().await?;

        .validate(&mut *conn)



  • 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.