diff --git a/src/domain/postgres/restore.rs b/src/domain/postgres/restore.rs index 1c6707e..2386715 100644 --- a/src/domain/postgres/restore.rs +++ b/src/domain/postgres/restore.rs @@ -15,8 +15,12 @@ use crate::services::backup::logger::JobLogger; use crate::services::config::DatabaseConfig; pub(crate) fn toc_creates_public_schema(toc: &str) -> bool { - toc.lines() - .any(|l| l.contains(" SCHEMA ") && l.trim_end().ends_with(" public")) + toc.lines().any(|l| { + l.split(" SCHEMA - ") + .nth(1) + .and_then(|rest| rest.split_whitespace().next()) + == Some("public") + }) } pub(crate) struct PreparedArchive { diff --git a/src/tests/domain/postgres.rs b/src/tests/domain/postgres.rs index b792c76..0f130a2 100644 --- a/src/tests/domain/postgres.rs +++ b/src/tests/domain/postgres.rs @@ -941,9 +941,11 @@ mod toc_tests { #[test] fn toc_public_schema_detection() { - let with = "123; 2615 12345 SCHEMA - public"; - let without = "200; 1259 12346 TABLE devschema users devuser"; + let with = "215; 2615 2200 SCHEMA - public pg_database_owner"; + let without_table = "200; 1259 12346 TABLE devschema users devuser"; + let without_similar_schema = "216; 2615 2201 SCHEMA - publicish someowner"; assert!(toc_creates_public_schema(with)); - assert!(!toc_creates_public_schema(without)); + assert!(!toc_creates_public_schema(without_table)); + assert!(!toc_creates_public_schema(without_similar_schema)); } }