From 916f1fccf246d3509eca8537f9428031f31a237a Mon Sep 17 00:00:00 2001 From: Kramer Hampton Date: Mon, 31 Aug 2020 17:42:22 -0400 Subject: [PATCH] feat: adds the reset command to the sqlx-cli The reset command is the equivalent of `sqlx db drop`, `sqlx db create`, and `sqlx migrate run`. Unless the `-y` parameter is specified, it will prompt confirmation before dropping the database. --- sqlx-cli/src/lib.rs | 5 +++++ sqlx-cli/src/opt.rs | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/sqlx-cli/src/lib.rs b/sqlx-cli/src/lib.rs index 1f1ca0598..40bd09173 100644 --- a/sqlx-cli/src/lib.rs +++ b/sqlx-cli/src/lib.rs @@ -39,6 +39,11 @@ hint: This command only works in the manifest directory of a Cargo package."# Command::Database(database) => match database.command { DatabaseCommand::Create => database::create(&database_url).await?, DatabaseCommand::Drop { yes } => database::drop(&database_url, !yes).await?, + DatabaseCommand::Reset { yes } => { + database::drop(&database_url, yes).await?; + database::create(&database_url).await?; + migrate::run(&database_url).await?; + } }, Command::Prepare { check: false, args } => prepare::run(&database_url, args)?, diff --git a/sqlx-cli/src/opt.rs b/sqlx-cli/src/opt.rs index a90b67e3b..0a0cc928a 100644 --- a/sqlx-cli/src/opt.rs +++ b/sqlx-cli/src/opt.rs @@ -57,6 +57,13 @@ pub enum DatabaseCommand { #[clap(short)] yes: bool, }, + /// Drops the database specified in your DATABASE_URL, re-creates it, and runs any pending migrations. + Reset { + /// Automatic confirmation. Without this option, you will be prompted before dropping + /// your database. + #[clap(short)] + yes: bool, + }, } /// Group of commands for creating and running migrations.