From 5c7b4cff93d15725c4bf1796ed0e6f3cfaf686ce Mon Sep 17 00:00:00 2001 From: Steffen Date: Mon, 30 Sep 2024 16:05:33 +0200 Subject: [PATCH] refactor(occurrences): fix migration --- src/Model/Migration/Definitions.hs | 36 +++++++++++++++++------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/Model/Migration/Definitions.hs b/src/Model/Migration/Definitions.hs index 9d5dec086..0f45bda71 100644 --- a/src/Model/Migration/Definitions.hs +++ b/src/Model/Migration/Definitions.hs @@ -219,7 +219,13 @@ customMigrations = mapF $ \case FROM tutorial AS t CROSS JOIN jsonb_array_elements(t."time"->'scheduled') AS elem GROUP BY t.id, t.room - ), updated_exceptions AS ( + ) + UPDATE tutorial AS t + SET "time" = jsonb_set(t."time", '{scheduled}', us.new_scheduled) + FROM updated_scheduled AS us + WHERE t.id = us.id + ; + WITH updated_exceptions AS ( SELECT id , jsonb_agg( CASE @@ -232,14 +238,10 @@ customMigrations = mapF $ \case GROUP BY t.id, t.room ) UPDATE tutorial AS t - SET "time" = jsonb_set( - jsonb_set(t."time", '{scheduled}', us.new_scheduled), - '{exceptions}', ue.new_exceptions - ) - FROM updated_scheduled AS us JOIN updated_exceptions AS ue ON us.id = ue.id - WHERE t.id = us.id + SET "time" = jsonb_set(t."time", '{exceptions}', ue.new_exceptions) + FROM updated_exceptions AS ue + WHERE t.id = ue.id ; - ALTER TABLE "tutorial" DROP COLUMN "room"; |] @@ -256,7 +258,13 @@ customMigrations = mapF $ \case FROM course_event AS t CROSS JOIN jsonb_array_elements(t."time"->'scheduled') AS elem GROUP BY t.id, t.room - ), updated_exceptions AS ( + ) + UPDATE course_event AS t + SET "time" = jsonb_set(t."time", '{scheduled}', us.new_scheduled) + FROM updated_scheduled AS us + WHERE t.id = us.id + ; + WITH updated_exceptions AS ( SELECT id , jsonb_agg( CASE @@ -269,14 +277,10 @@ customMigrations = mapF $ \case GROUP BY t.id, t.room ) UPDATE course_event AS t - SET "time" = jsonb_set( - jsonb_set(t."time", '{scheduled}', us.new_scheduled), - '{exceptions}', ue.new_exceptions - ) - FROM updated_scheduled AS us JOIN updated_exceptions AS ue ON us.id = ue.id - WHERE t.id = us.id + SET "time" = jsonb_set(t."time", '{exceptions}', ue.new_exceptions) + FROM updated_exceptions AS ue + WHERE t.id = ue.id ; - ALTER TABLE "course_event" DROP COLUMN "room"; |]