Do not update the createdAt column when importing postal code which does not change

The conflict resolution clause in the SQL command of the PostalCodeBaseImporter service has been updated. It now only changes the 'updatedAt' timestamp if either the 'center' position or the 'label' actually differs from the existing entry. This ensures that the 'updatedAt' field reflects when meaningful changes occurred.
This commit is contained in:
Julien Fastré 2024-07-19 13:42:48 +02:00
parent 19accc4d00
commit ad5e780936
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
2 changed files with 8 additions and 1 deletions

View File

@ -0,0 +1,6 @@
kind: Feature
body: Do not update the "createdAt" column when importing postal code which does not
change
time: 2024-07-19T13:42:41.208629736+02:00
custom:
Issue: ""

View File

@ -42,7 +42,8 @@ class PostalCodeBaseImporter
NOW(),
NOW()
FROM g
ON CONFLICT (code, refpostalcodeid, postalcodeSource) WHERE refpostalcodeid IS NOT NULL DO UPDATE SET label = excluded.label, center = excluded.center, updatedAt = NOW()
ON CONFLICT (code, refpostalcodeid, postalcodeSource) WHERE refpostalcodeid IS NOT NULL DO UPDATE
SET label = excluded.label, center = excluded.center, updatedAt = CASE WHEN NOT st_equals(excluded.center, chill_main_postal_code.center) OR excluded.label != chill_main_postal_code.label THEN NOW() ELSE chill_main_postal_code.updatedAt END
SQL;
private const VALUE = '(?, ?, ?, ?, ?, ?, ?, ?)';