Skip to content

Commit

Permalink
fix: one more error throw in case of table targeting not working
Browse files Browse the repository at this point in the history
  • Loading branch information
vjeeva committed Mar 19, 2024
1 parent 7a27cb8 commit d8e7cec
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pgbelt/util/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,16 @@ async def compare_data(
dst_old_extra_float_digits = await dst_pool.fetchval("SHOW extra_float_digits;")
await dst_pool.execute("SET extra_float_digits TO 0;")

has_run = False
for table in set(pkeys):
# If specific table list is defined and iterated table is not in that list, skip.
if tables and (table not in tables):
# If specific table list is defined and the iterated table is not in that list, skip.
# Note that the pkeys tables returned from Postgres are all lowercased, so we need to
# map the passed conf tables to lowercase.
if tables and (table not in list(map(str.lower, tables))):
continue

has_run = True # If this runs, we have at least one table to compare. We will use this flag to throw an error if no tables are found.

full_table_name = f"{schema}.{table}"

logger.debug(f"Validating table {full_table_name}...")
Expand Down Expand Up @@ -171,6 +177,13 @@ async def compare_data(
f"Dest Row: {dst_row}"
)

# Just a paranoia check. If this throws, then it's possible pgbelt didn't migrate any data.
# This was found in issue #420, and previous commands threw errors before this issue could arise.
if not has_run:
raise ValueError(
"No tables were found to compare. Please reach out to the pgbelt for help, and check if your data was migrated."
)

await src_pool.execute(f"SET extra_float_digits TO {src_old_extra_float_digits};")
await dst_pool.execute(f"SET extra_float_digits TO {dst_old_extra_float_digits};")
logger.info(
Expand Down

0 comments on commit d8e7cec

Please sign in to comment.