Skip to main content

ferro_cli/commands/
db_fresh.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!(
20        "{} Dropping all tables and re-running migrations...",
21        style("!!").yellow()
22    );
23    println!(
24        "{}",
25        style("WARNING: This will delete all data in your database!").red()
26    );
27
28    // Run cargo run -- db:fresh (unified binary)
29    let status = Command::new("cargo")
30        .args(["run", "--quiet", "--", "db:fresh"])
31        .status()
32        .expect("Failed to execute cargo command");
33
34    if !status.success() {
35        eprintln!("{} Fresh migration failed", style("Error:").red().bold());
36        std::process::exit(1);
37    }
38}