From b5d1617ec41e275848958320c5b91cc75950495a Mon Sep 17 00:00:00 2001 From: Yash Mehrotra Date: Thu, 22 Aug 2024 10:47:37 +0530 Subject: [PATCH] fix: handle first observed migration change (#974) --- functions/pre_alter_columns.sql | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/functions/pre_alter_columns.sql b/functions/pre_alter_columns.sql index 4252b42e..6a1b49db 100644 --- a/functions/pre_alter_columns.sql +++ b/functions/pre_alter_columns.sql @@ -3,7 +3,7 @@ BEGIN -- Check if the column "count" exists in the "config_changes" table IF EXISTS ( SELECT 1 - FROM information_schema.columns + FROM information_schema.columns WHERE table_schema = 'public' AND table_name = 'config_changes' AND column_name = 'count' @@ -15,12 +15,29 @@ BEGIN END IF; END $$; +DO $$ +BEGIN + -- Check if the column "first_observed" exists in the "config_changes" table + IF EXISTS ( + SELECT 1 + FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'config_changes' + AND column_name = 'first_observed' + ) THEN + -- Update existing NULL values in the "first_observed" column + UPDATE config_changes + SET first_observed = NOW() + WHERE first_observed IS NULL; + END IF; +END $$; + DO $$ BEGIN -- Check if the column "category" exists in the "playbooks" table IF EXISTS ( SELECT 1 - FROM information_schema.columns + FROM information_schema.columns WHERE table_schema = 'public' AND table_name = 'playbooks' AND column_name = 'category'