Fixes drop force option

pull/7240/head
gindibay 2023-11-13 14:19:19 +03:00
parent 52c9e92544
commit 3731c45c29
3 changed files with 51 additions and 1 deletions

View File

@ -329,8 +329,19 @@ AppendDropDatabaseStmt(StringInfo buf, DropdbStmt *stmt)
DefElem *option = NULL; DefElem *option = NULL;
foreach_ptr(option, stmt->options) 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) if (strcmp(option->defname, "force") == 0)
{ {
appendStringInfo(buf, "FORCE"); appendStringInfo(buf, "FORCE");
@ -341,6 +352,13 @@ AppendDropDatabaseStmt(StringInfo buf, DropdbStmt *stmt)
errmsg("unrecognized DROP DATABASE option \"%s\"", errmsg("unrecognized DROP DATABASE option \"%s\"",
option->defname))); option->defname)));
} }
//if it is the last option then append with ")"
if (option == llast(stmt->options))
{
appendStringInfo(buf, " )");
}
} }
} }

View File

@ -477,6 +477,24 @@ SET citus.enable_create_database_propagation TO ON;
DROP DATABASE test_node_activation; DROP DATABASE test_node_activation;
DROP DATABASE db_needs_escape; DROP DATABASE db_needs_escape;
DROP USER "role-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 --clean up resources created by this test
-- DROP TABLESPACE is not supported, so we need to drop it manually. -- DROP TABLESPACE is not supported, so we need to drop it manually.
SELECT result FROM run_command_on_all_nodes( SELECT result FROM run_command_on_all_nodes(

View File

@ -261,6 +261,20 @@ DROP DATABASE test_node_activation;
DROP DATABASE db_needs_escape; DROP DATABASE db_needs_escape;
DROP USER "role-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 --clean up resources created by this test
-- DROP TABLESPACE is not supported, so we need to drop it manually. -- DROP TABLESPACE is not supported, so we need to drop it manually.