Skip to main content

ferro_cli/commands/
db_rollback.rs

1use console::style;
2use std::path::Path;
3use std::process::Command;
4
5pub fn run(step: u32) {
6    // Check we're in a Ferro project
7    if !Path::new("src/migrations").exists() {
8        eprintln!(
9            "{} No migrations directory found at src/migrations",
10            style("Error:").red().bold()
11        );
12        eprintln!(
13            "{}",
14            style("Make sure you're in a Ferro project root directory.").dim()
15        );
16        std::process::exit(1);
17    }
18
19    println!(
20        "{} Rolling back {} migration(s)...",
21        style("->").cyan(),
22        step
23    );
24
25    // Run cargo run -- db:rollback <step> (unified binary)
26    let status = Command::new("cargo")
27        .args(["run", "--quiet", "--", "db:rollback", &step.to_string()])
28        .status()
29        .expect("Failed to execute cargo command");
30
31    if !status.success() {
32        eprintln!("{} Rollback failed", style("Error:").red().bold());
33        std::process::exit(1);
34    }
35}