//! Embedded SQL migrations. Runs against the manager's `PgPool` at
//! startup. New migrations live in `crates/manager-core/migrations/`
//! and follow the `NNNN_description.sql` convention.

use sqlx::PgPool;

pub async fn run(pool: &PgPool) -> Result<(), sqlx::migrate::MigrateError> {
    sqlx::migrate!("./migrations").run(pool).await
}

/// Highest embedded migration version. This is the schema version the
/// binary expects to find applied — surfaced from `/version` so peers
/// and operators can verify schema compatibility at a glance.
#[must_use]
pub fn latest_version() -> i64 {
    sqlx::migrate!("./migrations")
        .iter()
        .map(|m| m.version)
        .max()
        .unwrap_or(0)
}
