Adds validation for template

pull/7240/head
gindibay 2023-11-09 12:11:22 +03:00
parent 32c67963bd
commit 5f4092db5b
3 changed files with 32 additions and 68 deletions

View File

@ -259,18 +259,20 @@ DeparseAlterDatabaseSetStmt(Node *node)
static void static void
ValidateCreateDatabaseOptions(DefElem *option) ValidateCreateDatabaseOptions(DefElem *option)
{ {
if (strcmp(option->defname, "template") == 0 || if (strcmp(option->defname, "strategy") == 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)
{
ereport(ERROR, ereport(ERROR,
errmsg("CREATE DATABASE option \"%s\" is not supported", errmsg("CREATE DATABASE option \"%s\" is not supported",
option->defname)); 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"));
}
} }

View File

@ -12,8 +12,19 @@ CREATE TABLESPACE create_drop_db_tablespace LOCATION :'create_drop_db_tablespace
\c - - - :master_port \c - - - :master_port
create user create_drop_db_test_user; create user create_drop_db_test_user;
set citus.enable_create_database_propagation=on; set citus.enable_create_database_propagation=on;
-- Tests for create database propagation with template0 which should fail
CREATE DATABASE mydatabase CREATE DATABASE mydatabase
WITH OWNER = create_drop_db_test_user 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' ENCODING = 'UTF8'
CONNECTION LIMIT = 10 CONNECTION LIMIT = 10
TABLESPACE = create_drop_db_tablespace 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 DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
NOTICE: issuing DROP DATABASE IF EXISTS "mydatabase#1'2" NOTICE: issuing DROP DATABASE IF EXISTS "mydatabase#1'2"
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx 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 --clean up resources created by this test
drop tablespace create_drop_db_tablespace; drop tablespace create_drop_db_tablespace;
\c - - - :worker_1_port \c - - - :worker_1_port

View File

@ -18,9 +18,19 @@ create user create_drop_db_test_user;
set citus.enable_create_database_propagation=on; set citus.enable_create_database_propagation=on;
-- Tests for create database propagation with template0 which should fail
CREATE DATABASE mydatabase CREATE DATABASE mydatabase
WITH OWNER = create_drop_db_test_user 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' ENCODING = 'UTF8'
CONNECTION LIMIT = 10 CONNECTION LIMIT = 10
TABLESPACE = create_drop_db_tablespace TABLESPACE = create_drop_db_tablespace
@ -192,36 +202,6 @@ create database "mydatabase#1'2";
set citus.grep_remote_commands = '%DROP DATABASE%'; set citus.grep_remote_commands = '%DROP DATABASE%';
drop database if exists "mydatabase#1'2"; 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 --clean up resources created by this test