mirror of https://github.com/citusdata/citus.git
Support CREATE SCHEMA without name (#5782)
parent
e2424756bb
commit
551a7d1383
|
@ -223,7 +223,24 @@ CreateSchemaStmtObjectAddress(Node *node, bool missing_ok)
|
|||
{
|
||||
CreateSchemaStmt *stmt = castNode(CreateSchemaStmt, node);
|
||||
|
||||
return GetObjectAddressBySchemaName(stmt->schemaname, missing_ok);
|
||||
StringInfoData schemaName = { 0 };
|
||||
initStringInfo(&schemaName);
|
||||
|
||||
if (stmt->schemaname == NULL)
|
||||
{
|
||||
/*
|
||||
* If the schema name is not provided, the schema will be created
|
||||
* with the name of the authorizated user.
|
||||
*/
|
||||
Assert(stmt->authrole != NULL);
|
||||
appendStringInfoString(&schemaName, RoleSpecString(stmt->authrole, true));
|
||||
}
|
||||
else
|
||||
{
|
||||
appendStringInfoString(&schemaName, stmt->schemaname);
|
||||
}
|
||||
|
||||
return GetObjectAddressBySchemaName(schemaName.data, missing_ok);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -92,11 +92,6 @@ AppendCreateSchemaStmt(StringInfo buf, CreateSchemaStmt *stmt)
|
|||
elog(ERROR, "schema creating is not supported with other create commands");
|
||||
}
|
||||
|
||||
if (stmt->schemaname == NULL)
|
||||
{
|
||||
elog(ERROR, "schema name should be specified");
|
||||
}
|
||||
|
||||
appendStringInfoString(buf, "CREATE SCHEMA ");
|
||||
|
||||
if (stmt->if_not_exists)
|
||||
|
@ -104,7 +99,19 @@ AppendCreateSchemaStmt(StringInfo buf, CreateSchemaStmt *stmt)
|
|||
appendStringInfoString(buf, "IF NOT EXISTS ");
|
||||
}
|
||||
|
||||
if (stmt->schemaname != NULL)
|
||||
{
|
||||
appendStringInfo(buf, "%s ", quote_identifier(stmt->schemaname));
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* If the schema name is not provided, the schema will be created
|
||||
* with the name of the authorizated user.
|
||||
*/
|
||||
Assert(stmt->authrole != NULL);
|
||||
appendStringInfo(buf, "%s ", RoleSpecString(stmt->authrole, true));
|
||||
}
|
||||
|
||||
if (stmt->authrole != NULL)
|
||||
{
|
||||
|
|
|
@ -538,7 +538,28 @@ SELECT run_command_on_workers($$DROP SCHEMA localschema;$$);
|
|||
(localhost,57638,f,"ERROR: schema ""localschema"" does not exist")
|
||||
(2 rows)
|
||||
|
||||
CREATE ROLE schema_owner WITH LOGIN;
|
||||
NOTICE: not propagating CREATE ROLE/USER commands to worker nodes
|
||||
HINT: Connect to worker nodes directly to manually create all necessary users and roles.
|
||||
SELECT run_command_on_workers($$CREATE ROLE schema_owner WITH LOGIN;$$);
|
||||
run_command_on_workers
|
||||
---------------------------------------------------------------------
|
||||
(localhost,57637,t,"CREATE ROLE")
|
||||
(localhost,57638,t,"CREATE ROLE")
|
||||
(2 rows)
|
||||
|
||||
RESET citus.enable_ddl_propagation;
|
||||
-- create schema with the name of the owner
|
||||
CREATE SCHEMA AUTHORIZATION schema_owner;
|
||||
-- verify the schema is created on workers
|
||||
SELECT run_command_on_workers($$SELECT COUNT(*) FROM pg_namespace WHERE nspname='schema_owner';$$);
|
||||
run_command_on_workers
|
||||
---------------------------------------------------------------------
|
||||
(localhost,57637,t,1)
|
||||
(localhost,57638,t,1)
|
||||
(2 rows)
|
||||
|
||||
DROP SCHEMA schema_owner;
|
||||
DROP SCHEMA mx_old_schema CASCADE;
|
||||
DROP SCHEMA mx_new_schema CASCADE;
|
||||
NOTICE: drop cascades to table mx_new_schema.table_set_schema
|
||||
|
|
|
@ -351,7 +351,15 @@ CREATE SCHEMA localschema;
|
|||
-- should error out
|
||||
SELECT run_command_on_workers($$DROP SCHEMA localschema;$$);
|
||||
|
||||
CREATE ROLE schema_owner WITH LOGIN;
|
||||
SELECT run_command_on_workers($$CREATE ROLE schema_owner WITH LOGIN;$$);
|
||||
RESET citus.enable_ddl_propagation;
|
||||
-- create schema with the name of the owner
|
||||
CREATE SCHEMA AUTHORIZATION schema_owner;
|
||||
-- verify the schema is created on workers
|
||||
SELECT run_command_on_workers($$SELECT COUNT(*) FROM pg_namespace WHERE nspname='schema_owner';$$);
|
||||
|
||||
DROP SCHEMA schema_owner;
|
||||
|
||||
DROP SCHEMA mx_old_schema CASCADE;
|
||||
DROP SCHEMA mx_new_schema CASCADE;
|
||||
|
|
Loading…
Reference in New Issue