sntl-migrate 0.1.2

Migrations library + CLI helpers for Sentinel ORM
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use std::path::Path;

use crate::error::Result;

/// Pull the live schema and write it to `<cache_dir>/schema.toml`.
///
/// Called by `Migrator::run` after migrations apply so the compile-time
/// `query!()` cache always reflects the new schema. The caller controls
/// the cache directory.
pub async fn refresh_schema(conn_str: &str, cache_dir: &Path) -> Result<()> {
    let schema = sntl_schema::introspect::pull_schema(conn_str).await?;
    let cache = sntl_schema::cache::Cache::new(cache_dir);
    cache.init()?;
    cache.write_schema(&schema)?;
    Ok(())
}