From 3731c45c295c7ec862d9ef4e7eb6b96d485c5e35 Mon Sep 17 00:00:00 2001 From: gindibay Date: Mon, 13 Nov 2023 14:19:19 +0300 Subject: [PATCH] Fixes drop force option --- .../deparser/deparse_database_stmts.c | 20 ++++++++++++++++++- .../create_drop_database_propagation.out | 18 +++++++++++++++++ .../sql/create_drop_database_propagation.sql | 14 +++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/backend/distributed/deparser/deparse_database_stmts.c b/src/backend/distributed/deparser/deparse_database_stmts.c index 4551ccd1d..32b89b419 100644 --- a/src/backend/distributed/deparser/deparse_database_stmts.c +++ b/src/backend/distributed/deparser/deparse_database_stmts.c @@ -329,11 +329,22 @@ AppendDropDatabaseStmt(StringInfo buf, DropdbStmt *stmt) DefElem *option = NULL; + foreach_ptr(option, stmt->options) { + //if it is the first option then append with "WITH" else append with "," + if (option == linitial(stmt->options)) + { + appendStringInfo(buf, " WITH ( "); + } + else + { + appendStringInfo(buf, ", "); + } + if (strcmp(option->defname, "force") == 0) { - appendStringInfo(buf, " FORCE"); + appendStringInfo(buf, "FORCE"); } else { @@ -341,6 +352,13 @@ AppendDropDatabaseStmt(StringInfo buf, DropdbStmt *stmt) errmsg("unrecognized DROP DATABASE option \"%s\"", option->defname))); } + + //if it is the last option then append with ")" + if (option == llast(stmt->options)) + { + appendStringInfo(buf, " )"); + } + } } diff --git a/src/test/regress/expected/create_drop_database_propagation.out b/src/test/regress/expected/create_drop_database_propagation.out index 18bfa0c8a..7bd0cc8fa 100644 --- a/src/test/regress/expected/create_drop_database_propagation.out +++ b/src/test/regress/expected/create_drop_database_propagation.out @@ -477,6 +477,24 @@ SET citus.enable_create_database_propagation TO ON; DROP DATABASE test_node_activation; DROP DATABASE db_needs_escape; DROP USER "role-needs\!escape"; +-- drop database with force options test +create database db_force_test; +SET citus.log_remote_commands = true; +set citus.grep_remote_commands = '%DROP DATABASE%'; +drop database db_force_test with (force); +NOTICE: issuing DROP DATABASE db_force_test WITH ( FORCE ) +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +NOTICE: issuing DROP DATABASE db_force_test WITH ( FORCE ) +DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx +reset citus.log_remote_commands; +SELECT * FROM public.check_database_on_all_nodes('db_force_test') ORDER BY node_type; + node_type | result +--------------------------------------------------------------------- + coordinator (local) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false} + worker node (remote) | {"database_properties": null, "pg_dist_object_record_for_db_exists": false, "stale_pg_dist_object_record_for_a_db_exists": false} +(3 rows) + --clean up resources created by this test -- DROP TABLESPACE is not supported, so we need to drop it manually. SELECT result FROM run_command_on_all_nodes( diff --git a/src/test/regress/sql/create_drop_database_propagation.sql b/src/test/regress/sql/create_drop_database_propagation.sql index 6e6ecacb5..1b2f96da2 100644 --- a/src/test/regress/sql/create_drop_database_propagation.sql +++ b/src/test/regress/sql/create_drop_database_propagation.sql @@ -261,6 +261,20 @@ DROP DATABASE test_node_activation; DROP DATABASE db_needs_escape; DROP USER "role-needs\!escape"; +-- drop database with force options test + +create database db_force_test; + +SET citus.log_remote_commands = true; +set citus.grep_remote_commands = '%DROP DATABASE%'; + +drop database db_force_test with (force); + +reset citus.log_remote_commands; + +SELECT * FROM public.check_database_on_all_nodes('db_force_test') ORDER BY node_type; + + --clean up resources created by this test -- DROP TABLESPACE is not supported, so we need to drop it manually.