Skip to content
This repository was archived by the owner on Jun 27, 2024. It is now read-only.
Draft
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
6 changes: 5 additions & 1 deletion pgdatadiff/main.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""
Usage:
pgdatadiff --firstdb=<firstconnectionstring> --seconddb=<secondconnectionstring> [--only-data|--only-sequences] [--count-only] [--chunk-size=<size>]
pgdatadiff --firstdb=<firstconnectionstring> --seconddb=<secondconnectionstring> [--firstschemas=<firstschemas>] [--secondschemas=<secondschemas>] [--only-data|--only-sequences] [--count-only] [--chunk-size=<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
Expand All @@ -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'])

Expand Down
16 changes: 9 additions & 7 deletions pgdatadiff/pgdatadiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
],
Expand Down