From b72b1140b69108854a564d1f6ecea8e74ce054d0 Mon Sep 17 00:00:00 2001 From: Remington Campbell Date: Wed, 28 Oct 2020 20:35:54 -0700 Subject: [PATCH 1/4] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ec23877..fe4d4c0 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ install_requires=[ 'SQLAlchemy<=1.3.11', 'halo<=0.0.28', - 'psycopg2<=2.8.4', + 'psycopg2-binary', 'fabulous<=0.3.0', 'docopt<=0.6.2' ], From ee4a5d01e67edfd7e322eccf97d2f2a627f06db0 Mon Sep 17 00:00:00 2001 From: Remington Campbell Date: Wed, 28 Oct 2020 20:55:06 -0700 Subject: [PATCH 2/4] Add schemas to conn string --- pgdatadiff/main.py | 4 ++++ pgdatadiff/pgdatadiff.py | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pgdatadiff/main.py b/pgdatadiff/main.py index db41464..0cc9140 100644 --- a/pgdatadiff/main.py +++ b/pgdatadiff/main.py @@ -7,7 +7,9 @@ -h --help Show this screen. --version Show version. --firstdb=postgres://postgres:password@localhost/firstdb The connection string of the first DB + --firstschemas=public The schemas to compare in the first DB, comma separated --seconddb=postgres://postgres:password@localhost/seconddb The connection string of the second DB + --secondschemas=public The schemas to compare in the second DB, comma separated --only-data Only compare data, exclude sequences --only-sequences Only compare seqences, exclude data --count-only Do a quick test based on counts alone @@ -32,6 +34,8 @@ def main(): return 1 differ = DBDiff(first_db_connection_string, second_db_connection_string, + firstdb_schemas=arguments['--firstschemas'], + seconddb_schemas=arguments['--secondschemas'], chunk_size=arguments['--chunk-size'], count_only=arguments['--count-only']) diff --git a/pgdatadiff/pgdatadiff.py b/pgdatadiff/pgdatadiff.py index 1bb9be1..8c256c2 100644 --- a/pgdatadiff/pgdatadiff.py +++ b/pgdatadiff/pgdatadiff.py @@ -10,18 +10,18 @@ from sqlalchemy.sql.schema import MetaData, Table -def make_session(connection_string): +def make_session(connection_string, schemas): engine = create_engine(connection_string, echo=False, - convert_unicode=True) + convert_unicode=True, connect_args={'options': '-csearch_path={}'.format(schemas)}) Session = sessionmaker(bind=engine) return Session(), engine class DBDiff(object): - def __init__(self, firstdb, seconddb, chunk_size=10000, count_only=False): - firstsession, firstengine = make_session(firstdb) - secondsession, secondengine = make_session(seconddb) + def __init__(self, firstdb, seconddb, firstdb_schemas="public", seconddb_schemas="public", chunk_size=10000, count_only=False): + firstsession, firstengine = make_session(firstdb, firstdb_schemas) + secondsession, secondengine = make_session(seconddb, seconddb_schemas) self.firstsession = firstsession self.firstengine = firstengine self.secondsession = secondsession From f1646b6af4afeab49e8383431ac098d5dd2c0c9d Mon Sep 17 00:00:00 2001 From: Remington Campbell Date: Wed, 28 Oct 2020 20:57:56 -0700 Subject: [PATCH 3/4] Amend usage str --- pgdatadiff/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pgdatadiff/main.py b/pgdatadiff/main.py index 0cc9140..e96e503 100644 --- a/pgdatadiff/main.py +++ b/pgdatadiff/main.py @@ -1,6 +1,6 @@ """ Usage: - pgdatadiff --firstdb= --seconddb= [--only-data|--only-sequences] [--count-only] [--chunk-size=] + pgdatadiff --firstdb= --seconddb= [--firstschemas=] [--secondschemas=] [--only-data|--only-sequences] [--count-only] [--chunk-size=] pgdatadiff --version Options: From bc17c2957d9f1418325155f6c2578e2b32a681e4 Mon Sep 17 00:00:00 2001 From: Remington Campbell Date: Wed, 28 Oct 2020 21:01:18 -0700 Subject: [PATCH 4/4] Attempt meta schema --- pgdatadiff/pgdatadiff.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pgdatadiff/pgdatadiff.py b/pgdatadiff/pgdatadiff.py index 8c256c2..1549ef2 100644 --- a/pgdatadiff/pgdatadiff.py +++ b/pgdatadiff/pgdatadiff.py @@ -11,8 +11,10 @@ def make_session(connection_string, schemas): + #engine = create_engine(connection_string, echo=False, + # convert_unicode=True, connect_args={'options': '-csearch_path={}'.format(schemas)}) engine = create_engine(connection_string, echo=False, - convert_unicode=True, connect_args={'options': '-csearch_path={}'.format(schemas)}) + convert_unicode=True) Session = sessionmaker(bind=engine) return Session(), engine @@ -26,8 +28,8 @@ def __init__(self, firstdb, seconddb, firstdb_schemas="public", seconddb_schemas self.firstengine = firstengine self.secondsession = secondsession self.secondengine = secondengine - self.firstmeta = MetaData(bind=firstengine) - self.secondmeta = MetaData(bind=secondengine) + self.firstmeta = MetaData(bind=firstengine, schema=firstdb_schemas) + self.secondmeta = MetaData(bind=secondengine, schema=seconddb_schemas) self.firstinspector = inspect(firstengine) self.secondinspector = inspect(secondengine) self.chunk_size = int(chunk_size)