From ad5e7809361bceb7b25129512643b2cd110dbdef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 19 Jul 2024 13:42:48 +0200 Subject: [PATCH] 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. --- .changes/unreleased/Feature-20240719-134241.yaml | 6 ++++++ .../Service/Import/PostalCodeBaseImporter.php | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .changes/unreleased/Feature-20240719-134241.yaml diff --git a/.changes/unreleased/Feature-20240719-134241.yaml b/.changes/unreleased/Feature-20240719-134241.yaml new file mode 100644 index 000000000..89460cfc4 --- /dev/null +++ b/.changes/unreleased/Feature-20240719-134241.yaml @@ -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: "" diff --git a/src/Bundle/ChillMainBundle/Service/Import/PostalCodeBaseImporter.php b/src/Bundle/ChillMainBundle/Service/Import/PostalCodeBaseImporter.php index 5f7f52d72..36979ec87 100644 --- a/src/Bundle/ChillMainBundle/Service/Import/PostalCodeBaseImporter.php +++ b/src/Bundle/ChillMainBundle/Service/Import/PostalCodeBaseImporter.php @@ -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 = '(?, ?, ?, ?, ?, ?, ?, ?)';