tablediff.py
author Radek Brich <radek.brich@devl.cz>
Tue, 16 Aug 2011 15:12:53 +0200
changeset 8 2911935c524d
parent 7 685b20d2d3ab
child 9 2fcc8ef0b97d
permissions -rwxr-xr-x
pgmanager: Add keep_alive support.

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