Skip to content
This repository was archived by the owner on Jun 27, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ venv.bak/

# mypy
.mypy_cache/

# idea
.idea
30 changes: 29 additions & 1 deletion pgdatadiff/pgdatadiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,32 @@ def __init__(self, firstdb, seconddb, chunk_size=10000, count_only=False):
self.chunk_size = int(chunk_size)
self.count_only = count_only

def diff_sum_table_numeric_data(self):

SQL_NUMERIC_TABLES_AND_COLUMNS = f"""
SELECT table_name, column_name
FROM information_schema.columns
WHERE table_schema = 'public'
AND data_type = 'numeric';
"""

result_set = self.firstsession.execute(SQL_NUMERIC_TABLES_AND_COLUMNS).fetchall()

for row in result_set:
table_name = row['table_name']
column_name = row['column_name']

SQL_PAYMENT_TRANSACTION_SUM = f"""
SELECT sum({column_name})
FROM {table_name};
"""

first_sum_result = self.firstsession.execute(SQL_PAYMENT_TRANSACTION_SUM).fetchone()
second_sum_result = self.secondsession.execute(SQL_PAYMENT_TRANSACTION_SUM).fetchone()
if first_sum_result != second_sum_result:
print(bold(red(table_name + ' sum(' + column_name + ') is different')))
print(bold(green(table_name + ' sum(' + column_name + ') data is identical')))

def diff_table_data(self, tablename):
try:
firsttable = Table(tablename, self.firstmeta, autoload=True)
Expand Down Expand Up @@ -137,6 +163,9 @@ def diff_all_sequences(self):
def diff_all_table_data(self):
failures = 0
print(bold(red('Starting table analysis.')))

self.diff_sum_table_numeric_data()

with warnings.catch_warnings():
warnings.simplefilter("ignore", category=sa_exc.SAWarning)
tables = sorted(
Expand All @@ -158,4 +187,3 @@ def diff_all_table_data(self):
if failures > 0:
return 1
return 0