-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPgDiffFunctions.py
More file actions
64 lines (48 loc) · 2.62 KB
/
PgDiffFunctions.py
File metadata and controls
64 lines (48 loc) · 2.62 KB
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
from PgDiffUtils import PgDiffUtils
class PgDiffFunctions(object):
@staticmethod
def dropFunctions(writer, arguments, oldSchema, newSchema, searchPathHelper):
if oldSchema is None:
return
# Drop functions that exist no more
for oldFunctionSignature in oldSchema.functions:
if (oldFunctionSignature not in newSchema.functions):
searchPathHelper.outputSearchPath(writer)
writer.writeln(oldSchema.functions[oldFunctionSignature].getDropSQL())
@staticmethod
def createFunctions(writer, arguments, oldSchema, newSchema, searchPathHelper):
# Add new functions and replace modified functions
for newFunctionName, newFunction in newSchema.functions.items():
oldFunction = None
if oldSchema is not None:
oldFunction = oldSchema.functions.get(newFunction.getSignature())
if oldFunction is None or not newFunction.equals(oldFunction, arguments.ignoreFunctionWhitespace):
searchPathHelper.outputSearchPath(writer)
writer.writeln(newFunction.getCreationSQL())
@staticmethod
def alterComments(writer, oldSchema, newSchema, searchPathHelper):
if oldSchema is None:
return
for oldfunctionName, oldfunction in oldSchema.functions.items():
newFunction = newSchema.functions.get(oldfunction.getSignature())
if newFunction is None:
continue
if (oldfunction.comment is None and newFunction.comment is not None
or oldfunction.comment is not None
and newFunction.comment is not None
and oldfunction.comment != newFunction.comment):
searchPathHelper.outputSearchPath(writer)
writer.write("COMMENT ON FUNCTION ")
writer.write(PgDiffUtils.getQuotedName(newFunction.name))
writer.write('(')
writer.write(','.join(argument.getDeclaration(False) for argument in newFunction.arguments))
writer.write(") IS ")
writer.write(newFunction.comment)
writer.writeln(';')
elif (oldfunction.comment is not None and newFunction.comment is None):
searchPathHelper.outputSearchPath(writer)
writer.write("COMMENT ON FUNCTION ")
writer.write(PgDiffUtils.getQuotedName(newFunction.name))
writer.write('(')
writer.write(','.join(argument.getDeclaration(False) for argument in newFunction.arguments))
writer.writeln(") IS NULL;")