diff --git a/pgdatadiff/main.py b/pgdatadiff/main.py index db41464..e96e503 100644 --- a/pgdatadiff/main.py +++ b/pgdatadiff/main.py @@ -1,13 +1,15 @@ """ 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: -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..1549ef2 100644 --- a/pgdatadiff/pgdatadiff.py +++ b/pgdatadiff/pgdatadiff.py @@ -10,24 +10,26 @@ 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, connect_args={'options': '-csearch_path={}'.format(schemas)}) engine = create_engine(connection_string, echo=False, - convert_unicode=True) + convert_unicode=True) 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 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) 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' ],