mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-03-23 18:40:24 +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:
@@ -85,6 +85,30 @@ impl MigrateDatabase for Postgres {
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
fn force_drop_database(url: &str) -> BoxFuture<'_, Result<(), Error>> {
|
||||
Box::pin(async move {
|
||||
let (options, database) = parse_for_maintenance(url)?;
|
||||
let mut conn = options.connect().await?;
|
||||
|
||||
let row: (String,) = query_as("SELECT current_setting('server_version_num')")
|
||||
.fetch_one(&mut conn)
|
||||
.await?;
|
||||
|
||||
let version = row.0.parse::<i32>().unwrap();
|
||||
|
||||
let pid_type = if version >= 90200 { "pid" } else { "procpid" };
|
||||
|
||||
conn.execute(&*format!(
|
||||
"SELECT pg_terminate_backend(pg_stat_activity.{pid_type}) FROM pg_stat_activity \
|
||||
WHERE pg_stat_activity.datname = {} AND {pid_type} <> pg_backend_pid()",
|
||||
database.replace('"', "\"\""),
|
||||
))
|
||||
.await?;
|
||||
|
||||
Self::drop_database(url).await
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Migrate for PgConnection {
|
||||
|
||||
Reference in New Issue
Block a user