-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make drop queue infer queue type (#319)
* Make drop queue infer queue type * Overload function to not break backwards compatibility * Add migration file for drop_queue changes * Add test for automatic is_partitioned check * Drop function in migration script * Avoid code duplication in drop_queue * Refactor, add deprecation warning * fix * Include deprecation warnings in tests --------- Co-authored-by: Adam Hendel <ChuckHend@users.noreply.github.com> Co-authored-by: v0idpwn <v0idpwn@gmail.com>
- Loading branch information
1 parent
81f4a13
commit be39b73
Showing
5 changed files
with
133 additions
and
6 deletions.
There are no files selected for viewing
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
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,87 @@ | ||
DROP FUNCTION IF EXISTS pgmq.drop_queue(TEXT, BOOLEAN); | ||
|
||
CREATE FUNCTION pgmq.drop_queue(queue_name TEXT, partitioned BOOLEAN) | ||
RETURNS BOOLEAN AS $$ | ||
DECLARE | ||
qtable TEXT := pgmq.format_table_name(queue_name, 'q'); | ||
fq_qtable TEXT := 'pgmq.' || qtable; | ||
atable TEXT := pgmq.format_table_name(queue_name, 'a'); | ||
fq_atable TEXT := 'pgmq.' || atable; | ||
BEGIN | ||
RAISE WARNING "drop_queue(queue_name, partitioned) is deprecated and will be removed in PGMQ v2.0. Use drop_queue(queue_name) instead."; | ||
|
||
PERFORM pgmq.drop_queue(queue_name); | ||
|
||
RETURN TRUE; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
CREATE FUNCTION pgmq.drop_queue(queue_name TEXT) | ||
RETURNS BOOLEAN AS $$ | ||
DECLARE | ||
qtable TEXT := pgmq.format_table_name(queue_name, 'q'); | ||
fq_qtable TEXT := 'pgmq.' || qtable; | ||
atable TEXT := pgmq.format_table_name(queue_name, 'a'); | ||
fq_atable TEXT := 'pgmq.' || atable; | ||
partitioned BOOLEAN; | ||
BEGIN | ||
EXECUTE FORMAT( | ||
$QUERY$ | ||
SELECT is_partitioned FROM pgmq.meta WHERE queue_name = %L | ||
$QUERY$, | ||
queue_name | ||
) INTO partitioned; | ||
|
||
EXECUTE FORMAT( | ||
$QUERY$ | ||
ALTER EXTENSION pgmq DROP TABLE pgmq.%I | ||
$QUERY$, | ||
qtable | ||
); | ||
|
||
EXECUTE FORMAT( | ||
$QUERY$ | ||
ALTER EXTENSION pgmq DROP TABLE pgmq.%I | ||
$QUERY$, | ||
atable | ||
); | ||
|
||
EXECUTE FORMAT( | ||
$QUERY$ | ||
DROP TABLE IF EXISTS pgmq.%I | ||
$QUERY$, | ||
qtable | ||
); | ||
|
||
EXECUTE FORMAT( | ||
$QUERY$ | ||
DROP TABLE IF EXISTS pgmq.%I | ||
$QUERY$, | ||
atable | ||
); | ||
|
||
IF EXISTS ( | ||
SELECT 1 | ||
FROM information_schema.tables | ||
WHERE table_name = 'meta' and table_schema = 'pgmq' | ||
) THEN | ||
EXECUTE FORMAT( | ||
$QUERY$ | ||
DELETE FROM pgmq.meta WHERE queue_name = %L | ||
$QUERY$, | ||
queue_name | ||
); | ||
END IF; | ||
|
||
IF partitioned THEN | ||
EXECUTE FORMAT( | ||
$QUERY$ | ||
DELETE FROM %I.part_config where parent_table in (%L, %L) | ||
$QUERY$, | ||
pgmq._get_pg_partman_schema(), fq_qtable, fq_atable | ||
); | ||
END IF; | ||
|
||
RETURN TRUE; | ||
END; | ||
$$ LANGUAGE plpgsql; |
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
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
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