mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-03-19 08:39:44 +00:00
Sqlx Cli: Added force flag to drop database for postgres (#2873)
* Updated ahash so it can compile on mac * Updated MigrateDatabase Trait + related functions * Postgres force drop database flag impl * Update migrate.rs * Reverted MigrateDatabase Trait * Update migrate.rs * Update migrate.rs * Added force drop database fn impl * Add Migrate Error * Fixed changed function name
This commit is contained in:
@@ -23,7 +23,7 @@ pub async fn create(connect_opts: &ConnectOpts) -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn drop(connect_opts: &ConnectOpts, confirm: bool) -> anyhow::Result<()> {
|
||||
pub async fn drop(connect_opts: &ConnectOpts, confirm: bool, force: bool) -> anyhow::Result<()> {
|
||||
if confirm && !ask_to_continue_drop(connect_opts.required_db_url()?) {
|
||||
return Ok(());
|
||||
}
|
||||
@@ -33,7 +33,11 @@ pub async fn drop(connect_opts: &ConnectOpts, confirm: bool) -> anyhow::Result<(
|
||||
let exists = crate::retry_connect_errors(connect_opts, Any::database_exists).await?;
|
||||
|
||||
if exists {
|
||||
Any::drop_database(connect_opts.required_db_url()?).await?;
|
||||
if force {
|
||||
Any::force_drop_database(connect_opts.required_db_url()?).await?;
|
||||
} else {
|
||||
Any::drop_database(connect_opts.required_db_url()?).await?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -43,8 +47,9 @@ pub async fn reset(
|
||||
migration_source: &str,
|
||||
connect_opts: &ConnectOpts,
|
||||
confirm: bool,
|
||||
force: bool,
|
||||
) -> anyhow::Result<()> {
|
||||
drop(connect_opts, confirm).await?;
|
||||
drop(connect_opts, confirm, force).await?;
|
||||
setup(migration_source, connect_opts).await
|
||||
}
|
||||
|
||||
|
||||
@@ -74,12 +74,14 @@ pub async fn run(opt: Opt) -> Result<()> {
|
||||
DatabaseCommand::Drop {
|
||||
confirmation,
|
||||
connect_opts,
|
||||
} => database::drop(&connect_opts, !confirmation.yes).await?,
|
||||
force,
|
||||
} => database::drop(&connect_opts, !confirmation.yes, force).await?,
|
||||
DatabaseCommand::Reset {
|
||||
confirmation,
|
||||
source,
|
||||
connect_opts,
|
||||
} => database::reset(&source, &connect_opts, !confirmation.yes).await?,
|
||||
force,
|
||||
} => database::reset(&source, &connect_opts, !confirmation.yes, force).await?,
|
||||
DatabaseCommand::Setup {
|
||||
source,
|
||||
connect_opts,
|
||||
|
||||
@@ -76,6 +76,10 @@ pub enum DatabaseCommand {
|
||||
|
||||
#[clap(flatten)]
|
||||
connect_opts: ConnectOpts,
|
||||
|
||||
/// PostgreSQL only: force drops the database.
|
||||
#[clap(long, short, default_value = "false")]
|
||||
force: bool,
|
||||
},
|
||||
|
||||
/// Drops the database specified in your DATABASE_URL, re-creates it, and runs any pending migrations.
|
||||
@@ -88,6 +92,10 @@ pub enum DatabaseCommand {
|
||||
|
||||
#[clap(flatten)]
|
||||
connect_opts: ConnectOpts,
|
||||
|
||||
/// PostgreSQL only: force drops the database.
|
||||
#[clap(long, short, default_value = "false")]
|
||||
force: bool,
|
||||
},
|
||||
|
||||
/// Creates the database specified in your DATABASE_URL and runs any pending migrations.
|
||||
|
||||
Reference in New Issue
Block a user