Skip to content

PB-1403: Add tests for pgtriggers and clean up conditions. - #647

Merged
adk-swisstopo merged 10 commits into
developfrom
PB-1403-noraw2
Jun 4, 2026
Merged

PB-1403: Add tests for pgtriggers and clean up conditions.#647
adk-swisstopo merged 10 commits into
developfrom
PB-1403-noraw2

Conversation

@adk-swisstopo

Copy link
Copy Markdown
Member

As part of PB-1403 we need to modify several triggers which don't currently have tests. This change adds tests and modifies some of these triggers slightly to replace some raw SQL statements with calls to pgtrigger.AnyChange. No actual change in behaviour is expected at this stage.

One of the triggers generated by `child_triggers` is meant to update the
`updated` j field of the parent whenever the child changes. This is used for
the following relationships: item/Asset, collection/CollectionAsset,
collection/Item.

As part of PB-1403, I plan to modify these triggers.

This change adds tests to exercise these triggers. No change in behaviour is
expected at this point.
This turns four very redundant methods into one.
Set `db_create=True` everywhere.
The `generates_asset_upload_triggers` function generates a trigger that updates
the etag of an AssetUpload whenever any field of that AssetUpload is updated.
Before simplifying that trigger, I am adding a test to ensure it keeps working
as expected.
The `child_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 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 `child_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.

Something similar was done for `auto_variables_triggers` in 02f63bc
The `pgtrigger.Condition('OLD.file_size IS DISTINCT FROM NEW.file_size')`
condition is equivalent to `pgtrigger.AnyChange('file_size')`, which is easier
to inspect and reason about. This change replaces the former with the latter.
The `pgtrigger.Condition('''OLD.proj_epsg IS DISTINCT FROM NEW.proj_epsg''')`
condition is equivalent to `pgtrigger.AnyChange('proj_epsg')`, which is easier
to inspect and reason about. This change replaces the former with the latter.
The `pgtrigger.Condition('OLD.* IS DISTINCT FROM NEW.*')` condition is
equivalent to `pgtrigger.AnyChange()`, which is easier to inspect and reason
about. This change replaces the former with the latter.
The `pgtrigger.Condition('OLD.* IS DISTINCT FROM NEW.*')` condition is
equivalent to `pgtrigger.AnyChange()`, which is easier to inspect and reason
about. This change replaces the former with the latter.
@adk-swisstopo
adk-swisstopo merged commit 071f2f6 into develop Jun 4, 2026
3 checks passed
@adk-swisstopo
adk-swisstopo deleted the PB-1403-noraw2 branch June 4, 2026 07:14
@adk-swisstopo adk-swisstopo changed the title Add tests for pgtriggers and clean up conditions. PB-1403: Add tests for pgtriggers and clean up conditions. Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants