refactor(occurrences): fix migration
This commit is contained in:
parent
83fe750b15
commit
5c7b4cff93
@ -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";
|
||||
|]
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user