Set user as pg_merge_job_* schema owner

pull/1049/head
Marco Slot 2016-12-16 12:04:28 +01:00
parent 4914ccbaba
commit 42ff472721
1 changed files with 14 additions and 7 deletions

View File

@ -261,12 +261,8 @@ CreateJobSchema(StringInfo schemaName)
Oid savedUserId = InvalidOid; Oid savedUserId = InvalidOid;
int savedSecurityContext = 0; int savedSecurityContext = 0;
CreateSchemaStmt *createSchemaStmt = NULL;
/* build a CREATE SCHEMA statement */ RoleSpec currentUserRole = { 0 };
CreateSchemaStmt *createSchemaStmt = makeNode(CreateSchemaStmt);
createSchemaStmt->schemaname = schemaName->data;
createSchemaStmt->authrole = NULL;
createSchemaStmt->schemaElts = NIL;
/* allow schema names that start with pg_ */ /* allow schema names that start with pg_ */
oldAllowSystemTableMods = allowSystemTableMods; oldAllowSystemTableMods = allowSystemTableMods;
@ -276,7 +272,18 @@ CreateJobSchema(StringInfo schemaName)
GetUserIdAndSecContext(&savedUserId, &savedSecurityContext); GetUserIdAndSecContext(&savedUserId, &savedSecurityContext);
SetUserIdAndSecContext(CitusExtensionOwner(), SECURITY_LOCAL_USERID_CHANGE); SetUserIdAndSecContext(CitusExtensionOwner(), SECURITY_LOCAL_USERID_CHANGE);
/* actually create schema, and make it visible */ /* build a CREATE SCHEMA statement */
currentUserRole.type = T_RoleSpec;
currentUserRole.roletype = ROLESPEC_CSTRING;
currentUserRole.rolename = GetUserNameFromId(savedUserId, false);
currentUserRole.location = -1;
createSchemaStmt = makeNode(CreateSchemaStmt);
createSchemaStmt->schemaname = schemaName->data;
createSchemaStmt->authrole = (Node *) &currentUserRole;
createSchemaStmt->schemaElts = NIL;
/* actually create schema with the current user as owner */
CreateSchemaCommand(createSchemaStmt, queryString); CreateSchemaCommand(createSchemaStmt, queryString);
CommandCounterIncrement(); CommandCounterIncrement();