toasty_cli/migration/
reset.rs1use super::apply_migrations;
2use crate::Config;
3use crate::theme::dialoguer_theme;
4use anyhow::Result;
5use clap::Parser;
6use console::style;
7use dialoguer::Confirm;
8use toasty::Db;
9
10#[derive(Parser, Debug)]
11pub struct ResetCommand {
12 #[arg(long)]
14 skip_migrations: bool,
15}
16
17impl ResetCommand {
18 pub(crate) async fn run(self, db: &Db, config: &Config) -> Result<()> {
19 println!();
20 println!(" {}", style("Reset Database").cyan().bold().underlined());
21 println!();
22 println!(
23 " {}",
24 style(format!(
25 "Connected to {}",
26 crate::utility::redact_url_password(&db.driver().url())
27 ))
28 .dim()
29 );
30 println!();
31
32 let theme = {
33 let mut t = dialoguer_theme();
34 t.success_prefix = style(" ".to_string());
35 t.prompt_prefix = style(" ".to_string());
36 t.prompt_style = console::Style::new().red().bold();
37 t
38 };
39
40 let confirmed = Confirm::with_theme(&theme)
41 .with_prompt("This will drop all tables and data. Are you sure?")
42 .default(false)
43 .interact()?;
44
45 if !confirmed {
46 println!();
47 println!(" {}", style("Aborted.").dim());
48 println!();
49 return Ok(());
50 }
51
52 println!();
53 println!(" {} Resetting database...", style("→").cyan());
54
55 db.reset_db().await?;
56
57 println!(
58 " {} {}",
59 style("✓").green().bold(),
60 style("Database reset successfully").dim()
61 );
62 println!();
63
64 if !self.skip_migrations {
65 apply_migrations(db, config).await?;
66 }
67
68 Ok(())
69 }
70}