Skip to content

Commit 225de1f

Browse files
committed
Add additional flag to ignore tables in data comparison
1 parent 325db7a commit 225de1f

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

pgdatadiff/main.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
Usage:
3-
pgdatadiff --firstdb=<firstconnectionstring> --seconddb=<secondconnectionstring> [--only-data|--only-sequences] [--count-only] [--chunk-size=<size>]
3+
pgdatadiff --firstdb=<firstconnectionstring> --seconddb=<secondconnectionstring> [--only-data|--only-sequences] [--count-only] [--chunk-size=<size>] [--exclude-tables=<table1,table2>]
44
pgdatadiff --version
55
66
Options:
@@ -10,6 +10,7 @@
1010
--seconddb=postgres://postgres:password@localhost/seconddb The connection string of the second DB
1111
--only-data Only compare data, exclude sequences
1212
--only-sequences Only compare seqences, exclude data
13+
--exclude-tables="" Exclude tables from data comparison Must be a comma separated string [default: empty string]
1314
--count-only Do a quick test based on counts alone
1415
--chunk-size=10000 The chunk size when comparing data [default: 10000]
1516
"""
@@ -33,7 +34,8 @@ def main():
3334

3435
differ = DBDiff(first_db_connection_string, second_db_connection_string,
3536
chunk_size=arguments['--chunk-size'],
36-
count_only=arguments['--count-only'])
37+
count_only=arguments['--count-only'],
38+
exclude_tables=arguments['--exclude-tables'])
3739

3840
if not arguments['--only-sequences']:
3941
if differ.diff_all_table_data():

pgdatadiff/pgdatadiff.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import warnings
22

3-
from fabulous.color import bold, green, red
3+
from fabulous.color import bold, green, red, yellow
44
from halo import Halo
55
from sqlalchemy import exc as sa_exc
66
from sqlalchemy.engine import create_engine
@@ -19,7 +19,7 @@ def make_session(connection_string):
1919

2020
class DBDiff(object):
2121

22-
def __init__(self, firstdb, seconddb, chunk_size=10000, count_only=False):
22+
def __init__(self, firstdb, seconddb, chunk_size=10000, count_only=False, exclude_tables=""):
2323
firstsession, firstengine = make_session(firstdb)
2424
secondsession, secondengine = make_session(seconddb)
2525
self.firstsession = firstsession
@@ -32,6 +32,7 @@ def __init__(self, firstdb, seconddb, chunk_size=10000, count_only=False):
3232
self.secondinspector = inspect(secondengine)
3333
self.chunk_size = int(chunk_size)
3434
self.count_only = count_only
35+
self.exclude_tables = exclude_tables.split(',')
3536

3637
def diff_table_data(self, tablename):
3738
try:
@@ -142,6 +143,9 @@ def diff_all_table_data(self):
142143
tables = sorted(
143144
self.firstinspector.get_table_names(schema="public"))
144145
for table in tables:
146+
if table in self.exclude_tables:
147+
print(bold(yellow(f"Ignoring table {table}")))
148+
continue
145149
with Halo(
146150
text=f"Analysing table {table}. "
147151
f"[{tables.index(table) + 1}/{len(tables)}]",

0 commit comments

Comments
 (0)