fix: import into a cluster that has no such database yet

This commit is contained in:
2026-09-08 13:48:49 +00:00
parent 5239e000d7
commit cabbbde438

View File

@@ -21,8 +21,10 @@ pub struct DropDb<'a> {
impl Cmd for DropDb<'_> { impl Cmd for DropDb<'_> {
fn argv(&self) -> Argv { fn argv(&self) -> Argv {
// a cluster that never held this database is still a restore target
Argv::new("dropdb") Argv::new("dropdb")
.flag("--username", self.username) .flag("--username", self.username)
.arg("--if-exists")
.arg(self.dbname) .arg(self.dbname)
} }
} }
@@ -174,9 +176,22 @@ impl Cmd for PgDumpAll<'_> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::{PgDump, Psql}; use super::{DropDb, PgDump, Psql};
use crate::cmd::Cmd; 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] #[test]
fn a_directory_dump_names_the_file_it_writes() { fn a_directory_dump_names_the_file_it_writes() {
assert_eq!( assert_eq!(