-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix migration for drafts without recipients
- Loading branch information
1 parent
62072ec
commit 4132fd9
Showing
1 changed file
with
7 additions
and
4 deletions.
There are no files selected for viewing
11 changes: 7 additions & 4 deletions
11
service/src/main/resources/db/migration/V495__draft_message_recipients.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |