sqlx-migrate-validate

Crates.iosqlx-migrate-validate
lib.rssqlx-migrate-validate
version0.1.0
sourcesrc
created_at2023-03-13 02:39:45.482665
updated_at2023-03-13 02:39:45.482665
descriptionValidate your database sqlx migration state
homepagehttps://github.com/tobikris/sqlx-migrate-validate
repositoryhttps://github.com/tobikris/sqlx-migrate-validate
max_upload_size
id808469
size17,388
Tobias Krischer (tobikris)

documentation

https://github.com/tobikris/sqlx-migrate-validate

README

sqlx-migrate-validate

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.

Examples:

use sqlx_migrate_validate::{Validate, Validator};

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

    sqlx::migrate!("./tests/migrations-1")
        .validate(&mut *conn)
        .await?;

    Ok(())
}
Commit count: 1

cargo fmt