persistant 0.21.0

A thin persistence layer over Apache OpenDAL for blobs and records by key: declared capabilities, atomic replace, typed records, and a blocking facade for synchronous callers.
Documentation
// SPDX-License-Identifier: MIT OR Apache-2.0
//! Migrations: apply in order, run again safely, and refuse a migration that was edited.
//!
//! `cargo run --example migrations --features registry-sqlite` (a temporary SQLite file). The ledger
//! is sqlx's `_sqlx_migrations`; `persistant-migrate` does the same from a directory of files.

use persistant::relational::{MigrateError, Migrates, Migration};
use persistant::sqlx_driver::SqliteBackend;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let dir = tempfile::tempdir()?;
    let db = SqliteBackend::open(dir.path().join("example.db")).await?;

    let mut migrations = vec![
        Migration::new(
            1,
            "users",
            "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)",
        ),
        Migration::new(2, "email", "ALTER TABLE users ADD COLUMN email TEXT"),
    ];
    db.migrate(&migrations).await?;
    // A second run at the same versions changes nothing: this is what a program does at every start.
    db.migrate(&migrations).await?;
    assert_eq!(db.applied_versions().await?, [1, 2]);

    // Editing an applied migration is an error, never a silent re-run.
    migrations[0].sql.push_str(" -- edited");
    match db.migrate(&migrations).await {
        Err(MigrateError::ChecksumMismatch { version: 1 }) => println!("edit refused"),
        other => return Err(format!("expected a checksum mismatch, got {other:?}").into()),
    }
    Ok(())
}