@@ -63,7 +63,7 @@ def child_triggers(parent_name, child_name):
6363 name = f"update_{ parent_name } _child_trigger" ,
6464 operation = pgtrigger .Update ,
6565 when = pgtrigger .After ,
66- condition = pgtrigger .Condition ( 'OLD.* IS DISTINCT FROM NEW.*' ),
66+ condition = pgtrigger .AnyChange ( ),
6767 func = child_update_func .format (
6868 parent_name = parent_name , child_obj = "NEW" , child_name = child_name
6969 )
@@ -154,8 +154,7 @@ class IncreaseCounterTrigger(pgtrigger.Trigger):
154154 DecreaseCounterTrigger (
155155 name = f'upd_dec_{ value_field } _trigger' ,
156156 operation = pgtrigger .Update ,
157- condition = pgtrigger .
158- Condition (f'''OLD.{ value_field } IS DISTINCT FROM NEW.{ value_field } ''' )
157+ condition = pgtrigger .AnyChange (value_field )
159158 ),
160159 DecreaseCounterTrigger (
161160 name = f'del_{ value_field } _trigger' ,
@@ -164,8 +163,7 @@ class IncreaseCounterTrigger(pgtrigger.Trigger):
164163 IncreaseCounterTrigger (
165164 name = f'upd_inc_{ value_field } _trigger' ,
166165 operation = pgtrigger .Update ,
167- condition = pgtrigger .
168- Condition (f'''OLD.{ value_field } IS DISTINCT FROM NEW.{ value_field } ''' )
166+ condition = pgtrigger .AnyChange (value_field )
169167 ),
170168 IncreaseCounterTrigger (
171169 name = f'add_{ value_field } _trigger' ,
@@ -225,7 +223,7 @@ class ItemFileSizeTrigger(pgtrigger.Trigger):
225223 ItemFileSizeTrigger (
226224 name = 'update_asset_item_file_size_trigger' ,
227225 operation = pgtrigger .Update ,
228- condition = pgtrigger .Condition ( 'OLD.file_size IS DISTINCT FROM NEW. file_size' ),
226+ condition = pgtrigger .AnyChange ( ' file_size' ),
229227 )
230228 ]
231229
@@ -327,7 +325,7 @@ class IncreaseCounterTrigger(pgtrigger.Trigger):
327325 DecreaseCounterTrigger (
328326 name = 'upd_dec_col_asset_proj_epsg_trigger' ,
329327 operation = pgtrigger .Update ,
330- condition = pgtrigger .Condition ( '''OLD. proj_epsg IS DISTINCT FROM NEW.proj_epsg'' ' )
328+ condition = pgtrigger .AnyChange ( ' proj_epsg' )
331329 ),
332330 DecreaseCounterTrigger (
333331 name = 'del_col_asset_proj_epsg_trigger' ,
@@ -336,7 +334,7 @@ class IncreaseCounterTrigger(pgtrigger.Trigger):
336334 IncreaseCounterTrigger (
337335 name = 'upd_inc_col_asset_proj_epsg_trigger' ,
338336 operation = pgtrigger .Update ,
339- condition = pgtrigger .Condition ( '''OLD. proj_epsg IS DISTINCT FROM NEW.proj_epsg'' ' )
337+ condition = pgtrigger .AnyChange ( ' proj_epsg' )
340338 ),
341339 IncreaseCounterTrigger (
342340 name = 'add_col_asset_proj_epsg_trigger' ,
@@ -349,7 +347,7 @@ class IncreaseCounterTrigger(pgtrigger.Trigger):
349347 CollectionFileSizeTrigger (
350348 name = 'update_col_asset_col_file_size_trigger' ,
351349 operation = pgtrigger .Update ,
352- condition = pgtrigger .Condition ( 'OLD.* IS DISTINCT FROM NEW.*' ),
350+ condition = pgtrigger .AnyChange ( ),
353351 )
354352 ]
355353
@@ -415,11 +413,9 @@ class CollectionFileSizeTrigger(pgtrigger.Trigger):
415413 CollectionExtentTrigger (
416414 name = 'update_item_collection_extent_trigger' ,
417415 operation = pgtrigger .Update ,
418- condition = pgtrigger .Condition (
419- '''NOT ST_EQUALS(OLD.geometry, NEW.geometry) OR
420- OLD.properties_start_datetime IS DISTINCT FROM NEW.properties_start_datetime OR
421- OLD.properties_end_datetime IS DISTINCT FROM NEW.properties_end_datetime OR
422- OLD.properties_datetime IS DISTINCT FROM NEW.properties_datetime'''
416+ condition = (
417+ pgtrigger .Q (old__geometry__poly__equals = pgtrigger .F ('new__geometry' )) |
418+ pgtrigger .AnyChange ('start_datetime' , 'end_datetime' , 'datetime' )
423419 )
424420 ),
425421 CollectionExtentTrigger (
@@ -433,8 +429,7 @@ class CollectionFileSizeTrigger(pgtrigger.Trigger):
433429 CollectionFileSizeTrigger (
434430 name = 'update_item_collection_file_size_trigger' ,
435431 operation = pgtrigger .Update ,
436- condition = pgtrigger .
437- Condition ('OLD.total_data_size IS DISTINCT FROM NEW.total_data_size' ),
432+ condition = pgtrigger .AnyChange ('total_data_size' ),
438433 )
439434 ]
440435
@@ -480,7 +475,7 @@ def generates_asset_upload_triggers():
480475 pgtrigger .Trigger (
481476 name = "update_asset_upload_trigger" ,
482477 operation = pgtrigger .Update ,
483- condition = pgtrigger .Condition ( 'OLD.* IS DISTINCT FROM NEW.*' ),
478+ condition = pgtrigger .AnyChange ( ),
484479 when = pgtrigger .Before ,
485480 func = etag_func
486481 ),
@@ -531,7 +526,7 @@ class CollectionSummaryTrigger(pgtrigger.Trigger):
531526 operation = pgtrigger .Update ,
532527 # If the count is larger than 1 for OLD and NEW, the change has no impact on the list of
533528 # values, so we don't need to recalculate the summary.
534- condition = pgtrigger .Condition ( 'NOT (OLD.count > 1 AND NEW.count > 1)' )
529+ condition = ~ ( pgtrigger .Q ( old__count_gt = 1 ) & pgtrigger . Q ( new__count_gt = 1 ) )
535530 ),
536531 CollectionSummaryTrigger (
537532 name = f'add_del_collection_{ count_table } _trigger' ,
0 commit comments