author | Radek Brich <radek.brich@devl.cz> |
Fri, 09 Sep 2011 11:56:37 +0200 | |
changeset 13 | 16dc5dec9c36 |
parent 9 | 2fcc8ef0b97d |
child 14 | a900bc629ecc |
permissions | -rwxr-xr-x |
6 | 1 |
#!/usr/bin/env python3.2 |
2 |
# |
|
3 |
# Print differencies between data in two tables of same schema. |
|
4 |
# |
|
5 |
# Requirements: |
|
7
685b20d2d3ab
Reorganize directories. PgDataDiff - reworked. PgManager - add fetchone_adapted, fetchall_adapted to cursor.
Radek Brich <radek.brich@devl.cz>
parents:
6
diff
changeset
|
6 |
# * First column of both tables must be numerical primary key. |
6 | 7 |
# * Destination table must contain all columns from source table. |
8 |
# Order is not important. |
|
9 |
# |
|
10 |
||
9
2fcc8ef0b97d
Reorganize again :-) Add setup.py.
Radek Brich <radek.brich@devl.cz>
parents:
7
diff
changeset
|
11 |
from pgtoolkit import pgmanager, pgbrowser, pgdatadiff, toolbase |
6 | 12 |
|
13 |
||
7
685b20d2d3ab
Reorganize directories. PgDataDiff - reworked. PgManager - add fetchone_adapted, fetchall_adapted to cursor.
Radek Brich <radek.brich@devl.cz>
parents:
6
diff
changeset
|
14 |
class TableDiffTool(toolbase.SrcDstTool): |
6 | 15 |
def __init__(self): |
7
685b20d2d3ab
Reorganize directories. PgDataDiff - reworked. PgManager - add fetchone_adapted, fetchall_adapted to cursor.
Radek Brich <radek.brich@devl.cz>
parents:
6
diff
changeset
|
16 |
toolbase.SrcDstTool.__init__(self, name='tablediff', desc='Table diff.') |
6 | 17 |
|
18 |
self.parser.add_argument('table', metavar='table', type=str, help='Table name') |
|
7
685b20d2d3ab
Reorganize directories. PgDataDiff - reworked. PgManager - add fetchone_adapted, fetchall_adapted to cursor.
Radek Brich <radek.brich@devl.cz>
parents:
6
diff
changeset
|
19 |
self.parser.add_argument('-s', dest='schema', metavar='schema', type=str, default='public', help='Schema name.') |
685b20d2d3ab
Reorganize directories. PgDataDiff - reworked. PgManager - add fetchone_adapted, fetchall_adapted to cursor.
Radek Brich <radek.brich@devl.cz>
parents:
6
diff
changeset
|
20 |
self.parser.add_argument('--sql', action='store_true', help='Output is SQL script.') |
6 | 21 |
|
22 |
self.init() |
|
23 |
||
24 |
def main(self): |
|
7
685b20d2d3ab
Reorganize directories. PgDataDiff - reworked. PgManager - add fetchone_adapted, fetchall_adapted to cursor.
Radek Brich <radek.brich@devl.cz>
parents:
6
diff
changeset
|
25 |
table = self.args.table |
685b20d2d3ab
Reorganize directories. PgDataDiff - reworked. PgManager - add fetchone_adapted, fetchall_adapted to cursor.
Radek Brich <radek.brich@devl.cz>
parents:
6
diff
changeset
|
26 |
schema = self.args.schema |
6 | 27 |
|
7
685b20d2d3ab
Reorganize directories. PgDataDiff - reworked. PgManager - add fetchone_adapted, fetchall_adapted to cursor.
Radek Brich <radek.brich@devl.cz>
parents:
6
diff
changeset
|
28 |
dd = pgdatadiff.PgDataDiff(self.pgm.get_conn('src'), self.pgm.get_conn('dst')) |
685b20d2d3ab
Reorganize directories. PgDataDiff - reworked. PgManager - add fetchone_adapted, fetchall_adapted to cursor.
Radek Brich <radek.brich@devl.cz>
parents:
6
diff
changeset
|
29 |
dd.settable1(table, schema) |
685b20d2d3ab
Reorganize directories. PgDataDiff - reworked. PgManager - add fetchone_adapted, fetchall_adapted to cursor.
Radek Brich <radek.brich@devl.cz>
parents:
6
diff
changeset
|
30 |
dd.settable2(table, schema) |
6 | 31 |
|
7
685b20d2d3ab
Reorganize directories. PgDataDiff - reworked. PgManager - add fetchone_adapted, fetchall_adapted to cursor.
Radek Brich <radek.brich@devl.cz>
parents:
6
diff
changeset
|
32 |
if self.args.sql: |
685b20d2d3ab
Reorganize directories. PgDataDiff - reworked. PgManager - add fetchone_adapted, fetchall_adapted to cursor.
Radek Brich <radek.brich@devl.cz>
parents:
6
diff
changeset
|
33 |
dd.print_patch() |
685b20d2d3ab
Reorganize directories. PgDataDiff - reworked. PgManager - add fetchone_adapted, fetchall_adapted to cursor.
Radek Brich <radek.brich@devl.cz>
parents:
6
diff
changeset
|
34 |
else: |
685b20d2d3ab
Reorganize directories. PgDataDiff - reworked. PgManager - add fetchone_adapted, fetchall_adapted to cursor.
Radek Brich <radek.brich@devl.cz>
parents:
6
diff
changeset
|
35 |
dd.print_diff() |
6 | 36 |
|
37 |
||
38 |
tool = TableDiffTool() |
|
39 |
tool.main() |
|
7
685b20d2d3ab
Reorganize directories. PgDataDiff - reworked. PgManager - add fetchone_adapted, fetchall_adapted to cursor.
Radek Brich <radek.brich@devl.cz>
parents:
6
diff
changeset
|
40 |