From cabbbde4382d79420ede5ccbc7de00b099a99a9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Jane=C5=BEi=C4=8D?= Date: Tue, 8 Sep 2026 13:48:49 +0000 Subject: [PATCH] fix: import into a cluster that has no such database yet --- src/cmd/postgres.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/cmd/postgres.rs b/src/cmd/postgres.rs index a39269f..4154496 100644 --- a/src/cmd/postgres.rs +++ b/src/cmd/postgres.rs @@ -21,8 +21,10 @@ pub struct DropDb<'a> { impl Cmd for DropDb<'_> { fn argv(&self) -> Argv { + // a cluster that never held this database is still a restore target Argv::new("dropdb") .flag("--username", self.username) + .arg("--if-exists") .arg(self.dbname) } } @@ -174,9 +176,22 @@ impl Cmd for PgDumpAll<'_> { #[cfg(test)] mod tests { - use super::{PgDump, Psql}; + use super::{DropDb, PgDump, Psql}; use crate::cmd::Cmd; + #[test] + fn a_missing_database_is_not_a_failed_import() { + assert_eq!( + DropDb { + username: "u", + dbname: "db", + } + .argv() + .quoted(), + "dropdb --username u --if-exists db" + ); + } + #[test] fn a_directory_dump_names_the_file_it_writes() { assert_eq!(