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!(