mirror of https://github.com/citusdata/citus.git
Adds alter role rename
parent
1c3dfba637
commit
99e9786c7f
|
@ -152,12 +152,12 @@ static DistributeObjectOps Any_AlterRole = {
|
|||
};
|
||||
|
||||
static DistributeObjectOps Any_AlterRoleRename = {
|
||||
.deparse = DeparseAlterRoleStmt,
|
||||
.deparse = DeparseRenameRoleStmt,
|
||||
.qualify = NULL,
|
||||
.preprocess = NULL,
|
||||
.postprocess = PostprocessAlterRoleStmt,
|
||||
.preprocess = PreprocessAlterRoleRenameStmt,
|
||||
.postprocess = NULL,
|
||||
.operationType = DIST_OPS_ALTER,
|
||||
.address = AlterRoleStmtObjectAddress,
|
||||
.address = RenameRoleStmtObjectAddress,
|
||||
.markDistributed = false,
|
||||
};
|
||||
|
||||
|
@ -2072,7 +2072,7 @@ GetDistributeObjectOps(Node *node)
|
|||
|
||||
case OBJECT_ROLE:
|
||||
{
|
||||
return &Role_Rename;
|
||||
return &Any_AlterRoleRename;
|
||||
}
|
||||
|
||||
case OBJECT_ROUTINE:
|
||||
|
|
|
@ -1306,3 +1306,48 @@ EnsureSequentialModeForRoleDDL(void)
|
|||
"use only one connection for all future commands")));
|
||||
SetLocalMultiShardModifyModeToSequential();
|
||||
}
|
||||
|
||||
/*
|
||||
* PreprocessAlterDatabaseSetStmt is executed before the statement is applied to the local
|
||||
* postgres instance.
|
||||
*
|
||||
* In this stage we can prepare the commands that need to be run on all workers to grant
|
||||
* on databases.
|
||||
*/
|
||||
List *
|
||||
PreprocessAlterRoleRenameStmt(Node *node, const char *queryString,
|
||||
ProcessUtilityContext processUtilityContext)
|
||||
{
|
||||
if (!ShouldPropagate())
|
||||
{
|
||||
return NIL;
|
||||
}
|
||||
|
||||
RenameStmt *stmt = castNode(RenameStmt, node);
|
||||
Assert(stmt->renameType == OBJECT_ROLE);
|
||||
|
||||
|
||||
EnsureCoordinator();
|
||||
|
||||
char *sql = DeparseTreeNode((Node *) stmt);
|
||||
|
||||
List *commands = list_make3(DISABLE_DDL_PROPAGATION,
|
||||
(void *) sql,
|
||||
ENABLE_DDL_PROPAGATION);
|
||||
|
||||
return NodeDDLTaskList(NON_COORDINATOR_NODES, commands);
|
||||
}
|
||||
|
||||
|
||||
List *
|
||||
RenameRoleStmtObjectAddress(Node *node, bool missing_ok, bool isPostprocess)
|
||||
{
|
||||
RenameStmt *stmt = castNode(RenameStmt, node);
|
||||
Assert(stmt->renameType == OBJECT_ROLE);
|
||||
|
||||
Oid roleOid = get_role_oid(stmt->subname, missing_ok);
|
||||
ObjectAddress *address = palloc0(sizeof(ObjectAddress));
|
||||
ObjectAddressSet(*address, AuthIdRelationId, roleOid);
|
||||
|
||||
return list_make1(address);
|
||||
}
|
||||
|
|
|
@ -818,18 +818,6 @@ ProcessUtilityInternal(PlannedStmt *pstmt,
|
|||
}
|
||||
}
|
||||
|
||||
if (IsA(parsetree, RenameStmt) && ((RenameStmt *) parsetree)->renameType ==
|
||||
OBJECT_ROLE && EnableAlterRolePropagation)
|
||||
{
|
||||
if (EnableUnsupportedFeatureMessages)
|
||||
{
|
||||
ereport(NOTICE, (errmsg(
|
||||
"not propagating ALTER ROLE ... RENAME TO commands "
|
||||
"to worker nodes"),
|
||||
errhint("Connect to worker nodes directly to manually "
|
||||
"rename the role")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (IsA(parsetree, CreateStmt))
|
||||
|
|
|
@ -341,6 +341,22 @@ AppendRoleList(StringInfo buf, List *roleList)
|
|||
}
|
||||
|
||||
|
||||
char *
|
||||
DeparseRenameRoleStmt(Node *node)
|
||||
{
|
||||
RenameStmt *stmt = castNode(RenameStmt, node);
|
||||
StringInfoData str = { 0 };
|
||||
initStringInfo(&str);
|
||||
|
||||
Assert(stmt->renameType == OBJECT_ROLE);
|
||||
|
||||
appendStringInfo(&str, "ALTER ROLE %s RENAME TO %s;",
|
||||
quote_identifier(stmt->subname), quote_identifier(stmt->newname));
|
||||
|
||||
return str.data;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* DeparseGrantRoleStmt builds and returns a string representing of the
|
||||
* GrantRoleStmt for application on a remote server.
|
||||
|
|
|
@ -479,6 +479,10 @@ extern List * PreprocessRenameAttributeStmt(Node *stmt, const char *queryString,
|
|||
extern List * PostprocessAlterRoleStmt(Node *stmt, const char *queryString);
|
||||
extern List * PreprocessAlterRoleSetStmt(Node *stmt, const char *queryString,
|
||||
ProcessUtilityContext processUtilityContext);
|
||||
|
||||
extern List * PreprocessAlterRoleRenameStmt(Node *stmt, const char *queryString,
|
||||
ProcessUtilityContext processUtilityContext);
|
||||
|
||||
extern List * GenerateAlterRoleSetCommandForRole(Oid roleid);
|
||||
extern List * AlterRoleStmtObjectAddress(Node *node,
|
||||
bool missing_ok, bool isPostprocess);
|
||||
|
@ -494,6 +498,10 @@ extern List * PostprocessGrantRoleStmt(Node *stmt, const char *queryString);
|
|||
extern List * GenerateCreateOrAlterRoleCommand(Oid roleOid);
|
||||
extern List * CreateRoleStmtObjectAddress(Node *stmt, bool missing_ok, bool
|
||||
isPostprocess);
|
||||
|
||||
extern List * RenameRoleStmtObjectAddress(Node *stmt, bool missing_ok, bool
|
||||
isPostprocess);
|
||||
|
||||
extern void UnmarkRolesDistributed(List *roles);
|
||||
extern List * FilterDistributedRoles(List *roles);
|
||||
|
||||
|
|
|
@ -201,6 +201,7 @@ extern void QualifyAlterFunctionDependsStmt(Node *stmt);
|
|||
/* forward declarations for deparse_role_stmts.c */
|
||||
extern char * DeparseAlterRoleStmt(Node *stmt);
|
||||
extern char * DeparseAlterRoleSetStmt(Node *stmt);
|
||||
extern char * DeparseRenameRoleStmt(Node *stmt);
|
||||
|
||||
extern List * MakeSetStatementArguments(char *configurationName,
|
||||
char *configurationValue);
|
||||
|
|
|
@ -79,6 +79,7 @@ SELECT run_command_on_workers('SHOW enable_hashagg');
|
|||
-- check that ALTER ROLE SET is not propagated when scoped to a different database
|
||||
-- also test case sensitivity
|
||||
CREATE DATABASE "REGRESSION";
|
||||
|
||||
ALTER ROLE CURRENT_USER IN DATABASE "REGRESSION" SET public.myguc TO "Hello from coordinator only";
|
||||
SELECT d.datname, r.setconfig FROM pg_db_role_setting r LEFT JOIN pg_database d ON r.setdatabase=d.oid WHERE r.setconfig::text LIKE '%Hello from coordinator only%';
|
||||
SELECT run_command_on_workers($$SELECT json_agg((d.datname, r.setconfig)) FROM pg_db_role_setting r LEFT JOIN pg_database d ON r.setdatabase=d.oid WHERE r.setconfig::text LIKE '%Hello from coordinator only%'$$);
|
||||
|
@ -133,40 +134,21 @@ SELECT run_command_on_workers($$SELECT row(rolname, rolsuper, rolinherit, rolcr
|
|||
alter user test1 with password NULL superuser inherit createrole createdb login replication bypassrls connection limit 10 valid until '2019-01-01';
|
||||
SELECT run_command_on_workers($$SELECT row(rolname, rolsuper, rolinherit, rolcreaterole, rolcreatedb, rolcanlogin, rolreplication, rolbypassrls, rolconnlimit, EXTRACT (year FROM rolvaliduntil)) FROM pg_authid WHERE rolname = 'test1'$$);
|
||||
|
||||
|
||||
SET citus.enable_alter_role_set_propagation TO on;
|
||||
SET citus.log_remote_commands = true;
|
||||
-- Set a custom value for the search_path parameter
|
||||
ALTER USER test1 SET search_path TO public, schema2;
|
||||
set citus.grep_remote_commands = '%ALTER ROLE%';
|
||||
|
||||
-- Reset the search_path parameter to its default value
|
||||
ALTER USER test1 SET search_path TO DEFAULT;
|
||||
|
||||
-- Set a custom value for the timezone parameter
|
||||
ALTER USER test1 SET timezone TO 'America/New_York';
|
||||
|
||||
-- Reset the timezone parameter to its default value
|
||||
ALTER USER test1 SET timezone TO DEFAULT;
|
||||
|
||||
-- Set a custom value for the work_mem parameter
|
||||
ALTER USER test1 SET work_mem TO '64MB';
|
||||
|
||||
-- Reset the work_mem parameter to its default value
|
||||
ALTER USER test1 SET work_mem TO DEFAULT;
|
||||
|
||||
-- Set a custom value for the max_connections parameter
|
||||
ALTER USER test1 SET max_connections TO 100;
|
||||
|
||||
-- Reset the max_connections parameter to its default value
|
||||
ALTER USER test1 SET max_connections TO DEFAULT;
|
||||
|
||||
-- Set a custom float value for the random_page_cost parameter
|
||||
ALTER USER test1 SET random_page_cost TO 1.5;
|
||||
|
||||
|
||||
|
||||
alter user test1 rename to test2;
|
||||
|
||||
drop user if exists test2;
|
||||
|
||||
drop user test1;
|
||||
SET citus.log_remote_commands = false;
|
||||
|
||||
DROP TABLE test_search_path;
|
||||
DROP SCHEMA alter_role, ",CitUs,.TeeN!?", test_sp CASCADE;
|
||||
|
|
Loading…
Reference in New Issue