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.
This commit is contained in:
Kramer Hampton
2020-08-31 17:42:22 -04:00
committed by Austin Bonander
parent 44594e2e03
commit 916f1fccf2
2 changed files with 12 additions and 0 deletions

View File

@@ -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)?,

View File

@@ -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.