tablediff.py
author Radek Brich <radek.brich@devl.cz>
Fri, 12 Aug 2011 14:39:49 +0200
changeset 7 685b20d2d3ab
parent 6 4ab077c93b2d
child 9 2fcc8ef0b97d
permissions -rwxr-xr-x
Reorganize directories. PgDataDiff - reworked. PgManager - add fetchone_adapted, fetchall_adapted to cursor.

#!/usr/bin/env python3.2
#
# Print differencies between data in two tables of same schema.
#
# Requirements:
#  * First column of both tables must be numerical primary key.
#  * Destination table must contain all columns from source table.
#    Order is not important.
#

from tools import pgmanager, pgbrowser, pgdatadiff, toolbase


class TableDiffTool(toolbase.SrcDstTool):
    def __init__(self):
        toolbase.SrcDstTool.__init__(self, name='tablediff', desc='Table diff.')
        
        self.parser.add_argument('table', metavar='table', type=str, help='Table name')
        self.parser.add_argument('-s', dest='schema', metavar='schema', type=str, default='public', help='Schema name.')
        self.parser.add_argument('--sql', action='store_true', help='Output is SQL script.')
        
        self.init()

    def main(self):
        table = self.args.table
        schema = self.args.schema

        dd = pgdatadiff.PgDataDiff(self.pgm.get_conn('src'), self.pgm.get_conn('dst'))
        dd.settable1(table, schema)
        dd.settable2(table, schema)
        
        if self.args.sql:
            dd.print_patch()
        else:
            dd.print_diff()


tool = TableDiffTool()
tool.main()