PG16 compatibility - fix AM dependency and grant's admin option (#7113)

PG16 compatibility - part 11

Check out part 1 42d956888d
part 2 0d503dd5ac
part 3 907d72e60d
part 4 7c6b4ce103
part 5 6056cb2c29
part 6 b36c431abb
part 7 ee3153fe50
part 8 2c50b5f7ff
part 9 b2291374b4
part 10 a2315fdc67

This commit is in the series of PG16 compatibility commits. It fixes
AM dependency and grant's admin option:

- Fix with admin option in grants 
grantstmt->admin_opt no longer exists in PG16
instead, grantstmt has a list of options, one of them is admin option.
Relevant PG commit:
e3ce2de09d
e3ce2de09d814f8770b2e3b3c152b7671bcdb83f

- Fix pg_depend entry to AMs after ALTER TABLE .. SET ACCESS METHOD 
Relevant PG commit:
97d8910104
97d89101045fac8cb36f4ef6c08526ea0841a596


More PG16 compatibility commits are coming soon:
We are very close to merging "PG16Beta3 Support - Regression tests sanity"
pull/7116/head
Naisila Puka 2023-08-17 11:22:34 +03:00 committed by GitHub
parent 71c475af52
commit 9fa72545e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 8 deletions

View File

@ -819,12 +819,15 @@ GenerateGrantRoleStmtsFromOptions(RoleSpec *roleSpec, List *options)
grantRoleStmt->grantee_roles = list_make1(roleSpec); grantRoleStmt->grantee_roles = list_make1(roleSpec);
} }
#if PG_VERSION_NUM < PG_VERSION_16
if (strcmp(option->defname, "adminmembers") == 0) if (strcmp(option->defname, "adminmembers") == 0)
{ {
#if PG_VERSION_NUM >= PG_VERSION_16
DefElem *opt = makeDefElem("admin", (Node *) makeBoolean(true), -1);
grantRoleStmt->opt = list_make1(opt);
#else
grantRoleStmt->admin_opt = true; grantRoleStmt->admin_opt = true;
}
#endif #endif
}
stmts = lappend(stmts, grantRoleStmt); stmts = lappend(stmts, grantRoleStmt);
} }
@ -871,7 +874,13 @@ GenerateGrantRoleStmtsOfRole(Oid roleid)
grantRoleStmt->grantor = NULL; grantRoleStmt->grantor = NULL;
#if PG_VERSION_NUM < PG_VERSION_16 #if PG_VERSION_NUM >= PG_VERSION_16
if (membership->admin_option)
{
DefElem *opt = makeDefElem("admin", (Node *) makeBoolean(true), -1);
grantRoleStmt->opt = list_make1(opt);
}
#else
grantRoleStmt->admin_opt = membership->admin_option; grantRoleStmt->admin_opt = membership->admin_option;
#endif #endif

View File

@ -17,6 +17,7 @@
#include "distributed/citus_ruleutils.h" #include "distributed/citus_ruleutils.h"
#include "distributed/deparser.h" #include "distributed/deparser.h"
#include "distributed/listutils.h"
#include "lib/stringinfo.h" #include "lib/stringinfo.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
#include "utils/builtins.h" #include "utils/builtins.h"
@ -349,7 +350,20 @@ AppendGrantRoleStmt(StringInfo buf, GrantRoleStmt *stmt)
{ {
appendStringInfo(buf, "%s ", stmt->is_grant ? "GRANT" : "REVOKE"); appendStringInfo(buf, "%s ", stmt->is_grant ? "GRANT" : "REVOKE");
#if PG_VERSION_NUM < PG_VERSION_16 #if PG_VERSION_NUM >= PG_VERSION_16
if (!stmt->is_grant)
{
DefElem *opt = NULL;
foreach_ptr(opt, stmt->opt)
{
if (strcmp(opt->defname, "admin") == 0)
{
appendStringInfo(buf, "ADMIN OPTION FOR ");
break;
}
}
}
#else
if (!stmt->is_grant && stmt->admin_opt) if (!stmt->is_grant && stmt->admin_opt)
{ {
appendStringInfo(buf, "ADMIN OPTION FOR "); appendStringInfo(buf, "ADMIN OPTION FOR ");
@ -364,7 +378,17 @@ AppendGrantRoleStmt(StringInfo buf, GrantRoleStmt *stmt)
if (stmt->is_grant) if (stmt->is_grant)
{ {
#if PG_VERSION_NUM < PG_VERSION_16 #if PG_VERSION_NUM >= PG_VERSION_16
DefElem *opt = NULL;
foreach_ptr(opt, stmt->opt)
{
if (strcmp(opt->defname, "admin") == 0)
{
appendStringInfo(buf, " WITH ADMIN OPTION");
break;
}
}
#else
if (stmt->admin_opt) if (stmt->admin_opt)
{ {
appendStringInfo(buf, " WITH ADMIN OPTION"); appendStringInfo(buf, " WITH ADMIN OPTION");

View File

@ -1022,11 +1022,12 @@ GetUndistributableDependency(const ObjectAddress *objectAddress)
if (!SupportedDependencyByCitus(dependency)) if (!SupportedDependencyByCitus(dependency))
{ {
/* /*
* Since we do not yet support distributed TS TEMPLATE objects, we skip * Since we do not yet support distributed TS TEMPLATE and AM objects, we skip
* dependency checks for text search templates. The user is expected to * dependency checks for text search templates. The user is expected to
* manually create the TS TEMPLATE objects. * manually create the TS TEMPLATE and AM objects.
*/ */
if (getObjectClass(dependency) != OCLASS_TSTEMPLATE) if (getObjectClass(dependency) != OCLASS_TSTEMPLATE &&
getObjectClass(dependency) != OCLASS_AM)
{ {
return dependency; return dependency;
} }