From a662432fb5ffaa3e7ae4549a660b6b46753cb354 Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Wed, 11 Sep 2024 10:51:10 +0545 Subject: [PATCH] fix: config change update trigger we were reseting the created_at time of config changes everytime --- views/030_config_changes.sql | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/views/030_config_changes.sql b/views/030_config_changes.sql index 95139079..4926c60f 100644 --- a/views/030_config_changes.sql +++ b/views/030_config_changes.sql @@ -13,14 +13,16 @@ BEGIN WHEN NEW.details IS DISTINCT FROM OLD.details THEN NEW.count ELSE count END, - created_at = NOW(), + created_at = CASE + WHEN NEW.details IS DISTINCT FROM OLD.details THEN NOW() + ELSE COALESCE(NEW.created_at, OLD.created_at) + END, created_by = NEW.created_by, details = NEW.details, is_pushed = NEW.is_pushed, diff = NEW.diff, external_created_by = NEW.external_created_by, external_change_id = NEW.external_change_id, - first_observed = LEAST(first_observed, created_at), patches = NEW.patches, severity = NEW.severity, source = NEW.source, @@ -40,12 +42,14 @@ EXCEPTION WHEN NEW.details IS DISTINCT FROM OLD.details THEN config_changes.count + count_increment ELSE count END, - created_at = NOW(), + created_at = CASE + WHEN NEW.details IS DISTINCT FROM OLD.details THEN NOW() + ELSE COALESCE(NEW.created_at, OLD.created_at) + END, created_by = NEW.created_by, details = NEW.details, diff = NEW.diff, external_created_by = NEW.external_created_by, - first_observed = LEAST(first_observed, created_at), patches = NEW.patches, severity = NEW.severity, source = NEW.source,