PgDiff: Add patch support for SQL functions.
--- a/pgtoolkit/pgbrowser.py Tue Dec 10 11:39:57 2013 +0100
+++ b/pgtoolkit/pgbrowser.py Tue Feb 04 16:10:04 2014 +0100
@@ -127,6 +127,7 @@
self.mode = mode
self.default = default
+
class Function:
def __init__(self, browser, schema, oid, name, function_name, type, result, source):
self.browser = browser
@@ -416,7 +417,7 @@
oid: function oid from pg_catalog.pg_proc (returned by list_functions)
"""
- return self._query('''select pg_get_functiondef(%s);''', [oid])
+ return self._query('''SELECT pg_get_functiondef(%s) AS definition;''', [oid])[0]['definition']
def list_types(self, schema='public'):
"""List types in schema.
--- a/pgtoolkit/pgdiff.py Tue Dec 10 11:39:57 2013 +0100
+++ b/pgtoolkit/pgdiff.py Tue Feb 04 16:10:04 2014 +0100
@@ -137,13 +137,15 @@
class DiffFunction(DiffBase):
- def __init__(self, change, schema, function, show_body_diff=False):
+ def __init__(self, change, schema, function, definition, show_body_diff=False):
DiffBase.__init__(self)
self.level = 1
self.type = 'function'
self.change = change
self.schema = schema
self.function = function
+ #: New function definition
+ self.definition = definition
self.name = function
self.show_body_diff = show_body_diff
@@ -168,6 +170,9 @@
highlight(1,15), b, highlight(0), '.']))
return ' '.join(res)
+ def format_patch(self):
+ return [self.definition]
+
class DiffColumn(DiffBase):
ALTER_COMMANDS = {
@@ -484,7 +489,13 @@
for nd in self._diff_names(src_functions, dst_functions):
if not self._test_function(nd[1]):
continue
- fdo = DiffFunction(change=nd[0], schema=schema, function=nd[1], show_body_diff=self.function_body_diff)
+ if nd[1] in dst_functions:
+ dst_definition = dst_functions[nd[1]].definition
+ else:
+ dst_definition = None
+ fdo = DiffFunction(change=nd[0], schema=schema, function=nd[1],
+ definition=dst_definition,
+ show_body_diff=self.function_body_diff)
if nd[0] == '*':
# compare function body and result
a = src_functions[nd[1]]