Skip to main content

ferro_cli/commands/
db_migrate.rs

1use console::style;
2use std::path::Path;
3use std::process::Command;
4
5pub fn run() {
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("Run 'ferro make:migration <name>' to create your first migration.").dim()
15        );
16        std::process::exit(1);
17    }
18
19    println!("{} Running migrations...", style("->").cyan());
20
21    // Run cargo run -- db:migrate (unified binary)
22    let status = Command::new("cargo")
23        .args(["run", "--quiet", "--", "db:migrate"])
24        .status()
25        .expect("Failed to execute cargo command");
26
27    if !status.success() {
28        eprintln!("{} Migration failed", style("Error:").red().bold());
29        std::process::exit(1);
30    }
31}