refactor(occurrences): fix migration
This commit is contained in:
parent
83fe750b15
commit
5c7b4cff93
@ -219,7 +219,13 @@ customMigrations = mapF $ \case
|
|||||||
FROM tutorial AS t
|
FROM tutorial AS t
|
||||||
CROSS JOIN jsonb_array_elements(t."time"->'scheduled') AS elem
|
CROSS JOIN jsonb_array_elements(t."time"->'scheduled') AS elem
|
||||||
GROUP BY t.id, t.room
|
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
|
SELECT id
|
||||||
, jsonb_agg(
|
, jsonb_agg(
|
||||||
CASE
|
CASE
|
||||||
@ -232,14 +238,10 @@ customMigrations = mapF $ \case
|
|||||||
GROUP BY t.id, t.room
|
GROUP BY t.id, t.room
|
||||||
)
|
)
|
||||||
UPDATE tutorial AS t
|
UPDATE tutorial AS t
|
||||||
SET "time" = jsonb_set(
|
SET "time" = jsonb_set(t."time", '{exceptions}', ue.new_exceptions)
|
||||||
jsonb_set(t."time", '{scheduled}', us.new_scheduled),
|
FROM updated_exceptions AS ue
|
||||||
'{exceptions}', ue.new_exceptions
|
WHERE t.id = ue.id
|
||||||
)
|
|
||||||
FROM updated_scheduled AS us JOIN updated_exceptions AS ue ON us.id = ue.id
|
|
||||||
WHERE t.id = us.id
|
|
||||||
;
|
;
|
||||||
|
|
||||||
ALTER TABLE "tutorial" DROP COLUMN "room";
|
ALTER TABLE "tutorial" DROP COLUMN "room";
|
||||||
|]
|
|]
|
||||||
|
|
||||||
@ -256,7 +258,13 @@ customMigrations = mapF $ \case
|
|||||||
FROM course_event AS t
|
FROM course_event AS t
|
||||||
CROSS JOIN jsonb_array_elements(t."time"->'scheduled') AS elem
|
CROSS JOIN jsonb_array_elements(t."time"->'scheduled') AS elem
|
||||||
GROUP BY t.id, t.room
|
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
|
SELECT id
|
||||||
, jsonb_agg(
|
, jsonb_agg(
|
||||||
CASE
|
CASE
|
||||||
@ -269,14 +277,10 @@ customMigrations = mapF $ \case
|
|||||||
GROUP BY t.id, t.room
|
GROUP BY t.id, t.room
|
||||||
)
|
)
|
||||||
UPDATE course_event AS t
|
UPDATE course_event AS t
|
||||||
SET "time" = jsonb_set(
|
SET "time" = jsonb_set(t."time", '{exceptions}', ue.new_exceptions)
|
||||||
jsonb_set(t."time", '{scheduled}', us.new_scheduled),
|
FROM updated_exceptions AS ue
|
||||||
'{exceptions}', ue.new_exceptions
|
WHERE t.id = ue.id
|
||||||
)
|
|
||||||
FROM updated_scheduled AS us JOIN updated_exceptions AS ue ON us.id = ue.id
|
|
||||||
WHERE t.id = us.id
|
|
||||||
;
|
;
|
||||||
|
|
||||||
ALTER TABLE "course_event" DROP COLUMN "room";
|
ALTER TABLE "course_event" DROP COLUMN "room";
|
||||||
|]
|
|]
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user