Skip to content

Commit

Permalink
Fixes #41 mq_clear_ must keep the nil message (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
imbolc authored Jul 13, 2022
1 parent b332b6d commit 2fdabd9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- Add down migration script here
29 changes: 29 additions & 0 deletions migrations/20220713122907_fix-clear_all-keep-nil-message.up.sql
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';

0 comments on commit 2fdabd9

Please sign in to comment.