tablediff.py
changeset 14 a900bc629ecc
parent 9 2fcc8ef0b97d
child 34 98c7809af415
equal deleted inserted replaced
13:16dc5dec9c36 14:a900bc629ecc
    13 
    13 
    14 class TableDiffTool(toolbase.SrcDstTool):
    14 class TableDiffTool(toolbase.SrcDstTool):
    15     def __init__(self):
    15     def __init__(self):
    16         toolbase.SrcDstTool.__init__(self, name='tablediff', desc='Table diff.')
    16         toolbase.SrcDstTool.__init__(self, name='tablediff', desc='Table diff.')
    17         
    17         
    18         self.parser.add_argument('table', metavar='table', type=str, help='Table name')
    18         self.parser.add_argument('srctable', metavar='srctable',
    19         self.parser.add_argument('-s', dest='schema', metavar='schema', type=str, default='public', help='Schema name.')
    19             type=str, help='Source table name.')
       
    20         self.parser.add_argument('--dst-table', dest='dsttable', metavar='dsttable',
       
    21             type=str, default=None, help='Destination table (default=srctable).')
       
    22         self.parser.add_argument('-s', '--src-schema', dest='srcschema', metavar='srcschema',
       
    23             type=str, default='public', help='Schema name (default=public).')
       
    24         self.parser.add_argument('--dst-schema', dest='dstschema', metavar='dstschema',
       
    25             type=str, default=None, help='Destination schema name (default=srcschema).')
    20         self.parser.add_argument('--sql', action='store_true', help='Output is SQL script.')
    26         self.parser.add_argument('--sql', action='store_true', help='Output is SQL script.')
    21         
    27         
    22         self.init()
    28         self.init()
    23 
    29 
    24     def main(self):
    30     def main(self):
    25         table = self.args.table
    31         srcschema = self.args.srcschema
    26         schema = self.args.schema
    32         dstschema = self.args.dstschema if self.args.dstschema else self.args.srcschema
    27 
    33         
       
    34         srctable = self.args.srctable
       
    35         dsttable = self.args.dsttable if self.args.dsttable else self.args.srctable
       
    36         
    28         dd = pgdatadiff.PgDataDiff(self.pgm.get_conn('src'), self.pgm.get_conn('dst'))
    37         dd = pgdatadiff.PgDataDiff(self.pgm.get_conn('src'), self.pgm.get_conn('dst'))
    29         dd.settable1(table, schema)
    38         dd.settable1(srctable, srcschema)
    30         dd.settable2(table, schema)
    39         dd.settable2(dsttable, dstschema)
    31         
    40         
    32         if self.args.sql:
    41         if self.args.sql:
    33             dd.print_patch()
    42             dd.print_patch()
    34         else:
    43         else:
    35             dd.print_diff()
    44             dd.print_diff()