From cf3d8c295ec2c89190a3140bdf6b4c97ded8dbb9 Mon Sep 17 00:00:00 2001 From: Jesper Axelsson Date: Fri, 17 Apr 2020 09:54:50 +0200 Subject: [PATCH] Make sure user really want to drop their database --- cargo-sqlx/src/main.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cargo-sqlx/src/main.rs b/cargo-sqlx/src/main.rs index 22cf2f39..2ae7f49e 100644 --- a/cargo-sqlx/src/main.rs +++ b/cargo-sqlx/src/main.rs @@ -127,6 +127,8 @@ async fn run_create_database(db_creator: &dyn DatabaseMigrator) -> Result<()> { } async fn run_drop_database(db_creator: &dyn DatabaseMigrator) -> Result<()> { + use std::io; + if !db_creator.can_drop_database() { return Err(anyhow!( "Database drop is not implemented for {}", @@ -138,6 +140,24 @@ async fn run_drop_database(db_creator: &dyn DatabaseMigrator) -> Result<()> { let db_exists = db_creator.check_if_database_exists(&db_name).await?; if db_exists { + + loop { + println!("\nAre you sure you want to drop the database: {}? Y/n", db_name); + + let mut input = String::new(); + + io::stdin() + .read_line(&mut input) + .context("Failed to read line")?; + + match input.trim() { + "Y" => break, + "N" => return Ok(()), + "n" => return Ok(()), + _ => continue, + }; + }; + println!("Dropping database: {}", db_name); Ok(db_creator.drop_database(&db_name).await?) } else {