Skip to content

Commit 68ed5cd

Browse files
committed
Parameterise auto_variables_triggers.
The `auto_variables_triggers` function is used to generate PostgreSQL triggers to update some fields automatically. Currently it is triggered when any field changes. For PB-1403 we want at least one of these triggers to be conditional on specific fields. This change replaces the raw-SQL-based `Condition('OLD.* IS DISTINCT FROM NEW.*')` with `AnyChange(fields)`. This is equivalent as long as `fields` is empty. We also update `auto_variables_triggers` to take a new optional `fields` argument (defaulting to empty). This allows callers to define the conditions that apply for the trigger. A later change will make use of this new parametre.
1 parent 900c5ed commit 68ed5cd

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

app/stac_api/pgtriggers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pgtrigger
44

55

6-
def auto_variables_triggers(name):
6+
def auto_variables_triggers(name, *fields):
77
'''Triggers used by various tables to update the `etag` and `updated` fields.'''
88
auto_variables_func = '''
99
-- update auto variables
@@ -25,7 +25,7 @@ def auto_variables_triggers(name):
2525
name=f"update_{name}_auto_variables_trigger",
2626
operation=pgtrigger.Update,
2727
when=pgtrigger.Before,
28-
condition=pgtrigger.Condition('OLD.* IS DISTINCT FROM NEW.*'),
28+
condition=pgtrigger.AnyChange(fields),
2929
func=auto_variables_func
3030
)
3131
]

0 commit comments

Comments
 (0)