-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
migrations/20220713122907_fix-clear_all-keep-nil-message.down.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 |
---|---|---|
@@ -0,0 +1 @@ | ||
-- Add down migration script here |
29 changes: 29 additions & 0 deletions
29
migrations/20220713122907_fix-clear_all-keep-nil-message.up.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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
CREATE OR REPLACE FUNCTION mq_clear(channel_names TEXT[]) | ||
RETURNS VOID AS $$ | ||
BEGIN | ||
WITH deleted_ids AS ( | ||
DELETE FROM mq_msgs | ||
WHERE channel_name = ANY(channel_names) | ||
AND id != uuid_nil() | ||
RETURNING id | ||
) | ||
DELETE FROM mq_payloads WHERE id IN (SELECT id FROM deleted_ids); | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
COMMENT ON FUNCTION mq_clear IS | ||
'Deletes all messages with corresponding payloads from a list of channel names'; | ||
|
||
|
||
CREATE OR REPLACE FUNCTION mq_clear_all() | ||
RETURNS VOID AS $$ | ||
BEGIN | ||
WITH deleted_ids AS ( | ||
DELETE FROM mq_msgs | ||
WHERE id != uuid_nil() | ||
RETURNING id | ||
) | ||
DELETE FROM mq_payloads WHERE id IN (SELECT id FROM deleted_ids); | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
COMMENT ON FUNCTION mq_clear_all IS | ||
'Deletes all messages with corresponding payloads'; |