Skip to content

Commit

Permalink
Fix migration for drafts without recipients
Browse files Browse the repository at this point in the history
  • Loading branch information
terolaakso committed Feb 7, 2025
1 parent 62072ec commit 4132fd9
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
ALTER TABLE message_draft
ADD COLUMN recipients jsonb DEFAULT '[]'::jsonb;
ADD COLUMN recipients jsonb;

UPDATE message_draft
SET recipients = (SELECT jsonb_agg(jsonb_build_object('accountId', id, 'starter', false))
FROM (SELECT unnest(recipient_ids) AS id));
SET recipients = COALESCE(
(SELECT jsonb_agg(jsonb_build_object('accountId', id, 'starter', false))
FROM (SELECT unnest(recipient_ids) AS id))
, '[]'::jsonb);

ALTER TABLE message_draft
DROP COLUMN recipient_ids;
DROP COLUMN recipient_ids,
ALTER COLUMN recipients SET NOT NULL;

0 comments on commit 4132fd9

Please sign in to comment.