-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintegrityCheck.py
66 lines (53 loc) · 1.95 KB
/
integrityCheck.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: utf-8 -*-
from pgInfos import sqls
class integrityCheck:
__availableSide = ['left', 'right']
def __init__(self, dbLeft, dbRight):
self.__dbLeft = sqls(**dbLeft)
self.__dbRight = sqls(**dbRight)
def __checkMissingSide(self, side, left, right):
if not(side.lower() in type(self).__availableSide):
return []
missing = []
if side.lower() == 'right':
for c in left:
not(c in right) and missing.append(c)
else:
for c in right:
not(c in left) and missing.append(c)
return missing
def missingView(self, side):
lviews = self.__dbLeft.getAllPGClass(['v'])
rviews = self.__dbRight.getAllPGClass(['v'])
return self.checkMissingSide(side, lviews, rviews)
def missingMaterializedView(self, side):
lmviews = self.__dbLeft.getAllPGClass(['m'])
rmviews = self.__dbRight.getAllPGClass(['m'])
return self.checkMissingSide(side, lmviews, rmviews)
def missingTables(self, side):
ltable = self.__dbLeft.getAllPGClass(['r', 't', 'f', 'p'])
rtable = self.__dbRight.getAllPGClass(['r', 't', 'f', 'p'])
return self.checkMissingSide(side, ltable, rtable)
def searchNotMatchRows(self):
infos = {
'NotInRight': [],
'RowsNotEqual': [],
'NotInLeft': [],
'OK': []
}
lrows = self.__dbLeft.pgClassWithRowCount()
rrows = self.__dbRight.pgClassWithRowCount()
right = rrows
for c in lrows:
if not (c in rrows):
infos['NotInRight'].append(c)
continue
elif lrows[c] != rrows[c]:
infos['RowsNotEqual'].append(c)
else:
infos['OK'].append(c)
del right[c]
for c in right:
if not (c in lrows):
infos['NotInLeft'].append(c)
return infos