Skip to content
Snippets Groups Projects
Commit 5cf2f192 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

TMSS-421: check for changed column, not whole row.

parent bc63700f
Branches
Tags
1 merge request!262Resolve TMSS-421
...@@ -60,6 +60,13 @@ def makePostgresNotificationQueries(schema, table, action, column_name='id'): ...@@ -60,6 +60,13 @@ def makePostgresNotificationQueries(schema, table, action, column_name='id'):
elif action == 'DELETE': elif action == 'DELETE':
select_payload = '''SELECT '{"id": ' || CAST(OLD.id AS text) || '}' INTO payload;''' select_payload = '''SELECT '{"id": ' || CAST(OLD.id AS text) || '}' INTO payload;'''
if action == 'UPDATE':
begin_update_check = 'IF ROW(NEW.{what}) IS DISTINCT FROM ROW(OLD.{what}) THEN'.format(what='*' if column_name == 'id' else column_name)
end_update_check = 'END IF;'
else:
begin_update_check = ''
end_update_check = ''
function_sql = ''' function_sql = '''
CREATE OR REPLACE FUNCTION {schema}{function_name}() CREATE OR REPLACE FUNCTION {schema}{function_name}()
RETURNS TRIGGER AS $$ RETURNS TRIGGER AS $$
...@@ -79,9 +86,9 @@ def makePostgresNotificationQueries(schema, table, action, column_name='id'): ...@@ -79,9 +86,9 @@ def makePostgresNotificationQueries(schema, table, action, column_name='id'):
old_or_new=('OLD' if action == 'DELETE' else 'NEW') + '.' + column_name, old_or_new=('OLD' if action == 'DELETE' else 'NEW') + '.' + column_name,
value='OLD' if action == 'DELETE' else 'NEW', value='OLD' if action == 'DELETE' else 'NEW',
change_name=change_name.lower(), change_name=change_name.lower(),
begin_update_check='IF ROW(NEW.*) IS DISTINCT FROM ROW(OLD.*) THEN\n' if action == 'UPDATE' else '', begin_update_check=begin_update_check,
select_payload=select_payload, select_payload=select_payload,
end_update_check='\nEND IF;' if action == 'UPDATE' else '') end_update_check=end_update_check)
trigger_name = 'T_%s' % function_name trigger_name = 'T_%s' % function_name
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment