claw-core 0.1.2

Embedded local database engine for ClawDB — an agent-native cognitive database
Documentation
//! Embedded SQL migrations for claw-core.
//!
//! All schema migrations are embedded at compile time using SQLx's
//! `migrate!` macro. Migration files live in the `migrations/` directory at
//! the crate root. The [`run_migrations`] function applies all pending
//! migrations to the provided connection pool.

use sqlx::SqlitePool;

use crate::error::{ClawError, ClawResult};

/// Apply all pending embedded migrations to `pool`.
///
/// This function is called automatically by [`crate::engine::ClawEngine::open`]
/// when `auto_migrate` is enabled in the engine configuration.
///
/// # Errors
///
/// Returns a [`crate::error::ClawError::Migration`] if any migration step
/// fails.
pub async fn run_migrations(pool: &SqlitePool) -> ClawResult<()> {
    sqlx::migrate!("./migrations")
        .run(pool)
        .await
        .map_err(|e| ClawError::Migration(e.to_string()))?;
    Ok(())
}