Skip to content

Commit

Permalink
fix: remove-indexes syntax error fix (#630)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjeeva authored Nov 26, 2024
1 parent 06285e9 commit 4f779f9
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions pgbelt/util/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<index>[a-zA-Z0-9._]+)+.*",
Expand All @@ -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(
Expand Down

0 comments on commit 4f779f9

Please sign in to comment.