slave 0.7.0

CLI for slave, a Laravel-inspired Rust framework for MCP-first apps: scaffold an MCP backend with auth, roles and Turso migrations, add server-rendered web apps, and route them by domain or path
//! `slave migrate`, `migrate:status`, `migrate:rollback` and `migrate:fresh`.
//!
//! Migrations are Rust code compiled into the application, so these commands
//! build and run the application's `migrate` binary (`src/bin/migrate.rs`),
//! which drives the migration engine in `slave-framework`.

use anyhow::{Result, bail};

use crate::{cargo, project};

#[derive(Debug, Clone, Copy)]
pub enum Action {
    Run,
    Status,
    Rollback,
    /// Drop every table, then run all migrations.
    Fresh,
}

impl Action {
    fn arg(self) -> &'static str {
        match self {
            Self::Run => "run",
            Self::Status => "status",
            Self::Rollback => "rollback",
            Self::Fresh => "fresh",
        }
    }
}

pub fn run(action: Action) -> Result<()> {
    let root = project::find_root()?;
    if !root.join("src/bin/migrate.rs").is_file() {
        bail!(
            "src/bin/migrate.rs not found; this application was created without migration support"
        );
    }

    let status = cargo::run(
        &root,
        &["run", "--quiet", "--bin", "migrate", "--", action.arg()],
        &[],
    )?;
    if !status.success() {
        bail!("`{}` did not complete successfully", command_name(action));
    }
    Ok(())
}

fn command_name(action: Action) -> &'static str {
    match action {
        Action::Run => "slave migrate",
        Action::Status => "slave migrate:status",
        Action::Rollback => "slave migrate:rollback",
        Action::Fresh => "slave migrate:fresh",
    }
}