mirror of
https://github.com/Diggsey/sqlxmq.git
synced 2024-10-31 21:58:58 +00:00
parent
b332b6d826
commit
2fdabd9a98
2 changed files with 30 additions and 0 deletions
|
@ -0,0 +1 @@
|
|||
-- Add down migration script here
|
|
@ -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';
|
Loading…
Reference in a new issue