diff --git a/pgbelt/util/dump.py b/pgbelt/util/dump.py index 28a8aa8..0f85c5b 100644 --- a/pgbelt/util/dump.py +++ b/pgbelt/util/dump.py @@ -351,7 +351,6 @@ async def remove_dst_indexes(config: DbupgradeConfig, logger: Logger) -> None: logger.info("Removing Indexes from the target...") - queries = "" for c in create_index_statements.split(";"): regex_matches = search( r"CREATE [UNIQUE ]*INDEX (?P[a-zA-Z0-9._]+)+.*", @@ -360,14 +359,20 @@ async def remove_dst_indexes(config: DbupgradeConfig, logger: Logger) -> None: if not regex_matches: continue index = regex_matches.groupdict()["index"] + if config.schema_name: + index = f"{config.schema_name}.{index}" - queries = queries + f"DROP INDEX {index};" - - command = ["psql", config.dst.owner_dsn, "-c", f"'{queries}'"] + # DROP the index + # Note that the host DSN must have a statement timeout of 0. + # Example DSN: `host=server-hostname user=user dbname=db_name options='-c statement_timeout=3600000'` + host_dsn = config.dst.owner_dsn + " options='-c statement_timeout=0'" - await _execute_subprocess( - command, "Finished removing indexes from the target.", logger - ) + # DROP INDEX IF EXISTS so no need to catch exceptions + command = ["psql", host_dsn, "-c", f"DROP INDEX IF EXISTS {index};"] + logger.info(f"Dropping index {index} on the target...") + await _execute_subprocess( + command, f"Finished dropping index {index} on the target.", logger + ) async def create_target_indexes(