From 5f4092db5b7c89fb07a041cf1f1a22fdc75b2322 Mon Sep 17 00:00:00 2001 From: gindibay Date: Thu, 9 Nov 2023 12:11:22 +0300 Subject: [PATCH] Adds validation for template --- .../deparser/deparse_database_stmts.c | 18 ++++---- .../create_drop_database_propagation.out | 40 +++++------------- .../sql/create_drop_database_propagation.sql | 42 +++++-------------- 3 files changed, 32 insertions(+), 68 deletions(-) diff --git a/src/backend/distributed/deparser/deparse_database_stmts.c b/src/backend/distributed/deparser/deparse_database_stmts.c index a0b9ea7ba..a06263721 100644 --- a/src/backend/distributed/deparser/deparse_database_stmts.c +++ b/src/backend/distributed/deparser/deparse_database_stmts.c @@ -259,18 +259,20 @@ DeparseAlterDatabaseSetStmt(Node *node) static void ValidateCreateDatabaseOptions(DefElem *option) { - if (strcmp(option->defname, "template") == 0 || - strcmp(option->defname, "strategy") == 0 || - strcmp(option->defname, "lc_ctype") == 0 || - strcmp(option->defname, "locale") == 0 || - strcmp(option->defname, "lc_collate") == 0 || - strcmp(option->defname, "icu_locale") == 0 || - strcmp(option->defname, "locale_provider") == 0) - { + if (strcmp(option->defname, "strategy") == 0){ ereport(ERROR, errmsg("CREATE DATABASE option \"%s\" is not supported", option->defname)); } + + char *optionValue = defGetString(option); + if (strcmp(option->defname,"template") == 0 && strcmp(optionValue, "template1") != 0) + { + + ereport(ERROR,errmsg("Only template1 is supported as template parameter for CREATE DATABASE")); + + } + } diff --git a/src/test/regress/expected/create_drop_database_propagation.out b/src/test/regress/expected/create_drop_database_propagation.out index 9489664eb..c5ab0e2df 100644 --- a/src/test/regress/expected/create_drop_database_propagation.out +++ b/src/test/regress/expected/create_drop_database_propagation.out @@ -12,8 +12,19 @@ CREATE TABLESPACE create_drop_db_tablespace LOCATION :'create_drop_db_tablespace \c - - - :master_port create user create_drop_db_test_user; set citus.enable_create_database_propagation=on; +-- Tests for create database propagation with template0 which should fail CREATE DATABASE mydatabase WITH OWNER = create_drop_db_test_user + TEMPLATE = 'template0' + ENCODING = 'UTF8' + CONNECTION LIMIT = 10 + TABLESPACE = create_drop_db_tablespace + ALLOW_CONNECTIONS = true + IS_TEMPLATE = false; +ERROR: Only template1 is supported as template parameter for CREATE DATABASE +CREATE DATABASE mydatabase + WITH template=template1 + OWNER = create_drop_db_test_user ENCODING = 'UTF8' CONNECTION LIMIT = 10 TABLESPACE = create_drop_db_tablespace @@ -239,35 +250,6 @@ NOTICE: issuing DROP DATABASE IF EXISTS "mydatabase#1'2" DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx NOTICE: issuing DROP DATABASE IF EXISTS "mydatabase#1'2" DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx ---test for unsupported options -CREATE DATABASE mydatabase - with CONNECTION LIMIT = 10 - ENCODING = 'UTF8' - LC_CTYPE = 'C.UTF-8' - ALLOW_CONNECTIONS = false - IS_TEMPLATE = false; -ERROR: CREATE DATABASE option "lc_ctype" is not supported -CREATE DATABASE mydatabase - with CONNECTION LIMIT = 10 - ENCODING = 'UTF8' - LC_CTYPE = 'C.UTF-8' - ALLOW_CONNECTIONS = false - IS_TEMPLATE = false; -ERROR: CREATE DATABASE option "lc_ctype" is not supported -CREATE DATABASE mydatabase - with CONNECTION LIMIT = 10 - ENCODING = 'UTF8' - LC_COLLATE = 'C.UTF-8' - ALLOW_CONNECTIONS = false - IS_TEMPLATE = false; -ERROR: CREATE DATABASE option "lc_collate" is not supported -CREATE DATABASE mydatabase - with CONNECTION LIMIT = 10 - ENCODING = 'UTF8' - LOCALE = 'C.UTF-8' - ALLOW_CONNECTIONS = false - IS_TEMPLATE = false; -ERROR: CREATE DATABASE option "locale" is not supported --clean up resources created by this test drop tablespace create_drop_db_tablespace; \c - - - :worker_1_port diff --git a/src/test/regress/sql/create_drop_database_propagation.sql b/src/test/regress/sql/create_drop_database_propagation.sql index ae90088d1..157c70b28 100644 --- a/src/test/regress/sql/create_drop_database_propagation.sql +++ b/src/test/regress/sql/create_drop_database_propagation.sql @@ -18,9 +18,19 @@ create user create_drop_db_test_user; set citus.enable_create_database_propagation=on; - +-- Tests for create database propagation with template0 which should fail CREATE DATABASE mydatabase WITH OWNER = create_drop_db_test_user + TEMPLATE = 'template0' + ENCODING = 'UTF8' + CONNECTION LIMIT = 10 + TABLESPACE = create_drop_db_tablespace + ALLOW_CONNECTIONS = true + IS_TEMPLATE = false; + +CREATE DATABASE mydatabase + WITH template=template1 + OWNER = create_drop_db_test_user ENCODING = 'UTF8' CONNECTION LIMIT = 10 TABLESPACE = create_drop_db_tablespace @@ -192,36 +202,6 @@ create database "mydatabase#1'2"; set citus.grep_remote_commands = '%DROP DATABASE%'; drop database if exists "mydatabase#1'2"; ---test for unsupported options - -CREATE DATABASE mydatabase - with CONNECTION LIMIT = 10 - ENCODING = 'UTF8' - LC_CTYPE = 'C.UTF-8' - ALLOW_CONNECTIONS = false - IS_TEMPLATE = false; - -CREATE DATABASE mydatabase - with CONNECTION LIMIT = 10 - ENCODING = 'UTF8' - LC_CTYPE = 'C.UTF-8' - ALLOW_CONNECTIONS = false - IS_TEMPLATE = false; - -CREATE DATABASE mydatabase - with CONNECTION LIMIT = 10 - ENCODING = 'UTF8' - LC_COLLATE = 'C.UTF-8' - ALLOW_CONNECTIONS = false - IS_TEMPLATE = false; - -CREATE DATABASE mydatabase - with CONNECTION LIMIT = 10 - ENCODING = 'UTF8' - LOCALE = 'C.UTF-8' - ALLOW_CONNECTIONS = false - IS_TEMPLATE = false; - --clean up resources created by this test