tablediff.py
author Radek Brich <radek.brich@devl.cz>
Tue, 06 Sep 2011 17:55:15 +0200
changeset 12 203be9022b46
parent 9 2fcc8ef0b97d
child 14 a900bc629ecc
permissions -rwxr-xr-x
Fix pgdatadiff.

#!/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 pgtoolkit 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()