bloom-web-core 0.1.1

Core functionality for the Bloom web framework
use std::future::Future;
use std::pin::Pin;

use anyhow::Result;
use sqlx::MySqlPool;

/// A migration entry registered by each Entity derive.
///
/// This struct represents a database migration that can be executed to create
/// or modify database tables. Each migration has a name and a run function.
pub struct Migration {
    pub name: &'static str,
    pub run: for<'a> fn(&'a MySqlPool) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>>,
}

inventory::collect!(Migration);

/// Runs all registered migrations in sequence.
///
/// This function iterates through all migrations registered via the inventory
/// system and executes them against the provided database pool.
///
/// # Arguments
/// * `pool` - The MySQL connection pool to execute migrations against
///
/// # Returns
/// * `Result<()>` - Ok if all migrations succeed, Err if any migration fails
pub async fn run_all(pool: &MySqlPool) -> Result<()> {
    for mig in inventory::iter::<Migration> {
        (mig.run)(pool).await?;
    }
    Ok(())
}