From e66d3c351b3f2e37c3afa79cda446fce38281b6e Mon Sep 17 00:00:00 2001 From: Varjitt Jeeva Date: Mon, 25 Nov 2024 12:24:13 -0500 Subject: [PATCH] fix: remove-constraints errors if no NOT VALIDS involved --- pgbelt/util/dump.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pgbelt/util/dump.py b/pgbelt/util/dump.py index bfb2f7d..2858d20 100644 --- a/pgbelt/util/dump.py +++ b/pgbelt/util/dump.py @@ -310,11 +310,14 @@ async def remove_dst_not_valid_constraints( if (config.tables and table in config.tables) or not config.tables: queries = queries + f"ALTER TABLE {table} DROP CONSTRAINT {constraint};" - command = ["psql", config.dst.owner_dsn, "-c", f"'{queries}'"] + if queries != "": + command = ["psql", config.dst.owner_dsn, "-c", f"'{queries}'"] - await _execute_subprocess( - command, "Finished removing NOT VALID constraints from the target.", logger - ) + await _execute_subprocess( + command, "Finished removing NOT VALID constraints from the target.", logger + ) + else: + logger.info("No NOT VALID detected for removal.") async def apply_target_constraints(config: DbupgradeConfig, logger: Logger) -> None: