Avoid using DefElemAction in AlterPublicationStmt

Create a new enum type for it.  This allows to add new values for future
functionality without disrupting unrelated uses of DefElem.

Discussion: https://postgr.es/m/202112302021.ca7ihogysgh3@alvherre.pgsql
This commit is contained in:
Alvaro Herrera 2022-01-03 10:48:48 -03:00
parent 234ba62769
commit 9623d89996
No known key found for this signature in database
GPG Key ID: 1C20ACB9D5C564AE
3 changed files with 21 additions and 14 deletions

View File

@ -503,12 +503,12 @@ AlterPublicationTables(AlterPublicationStmt *stmt, HeapTuple tup,
* possible that user has not specified any tables in which case we need * possible that user has not specified any tables in which case we need
* to remove all the existing tables. * to remove all the existing tables.
*/ */
if (!tables && stmt->action != DEFELEM_SET) if (!tables && stmt->action != AP_SetObjects)
return; return;
rels = OpenTableList(tables); rels = OpenTableList(tables);
if (stmt->action == DEFELEM_ADD) if (stmt->action == AP_AddObjects)
{ {
List *schemas = NIL; List *schemas = NIL;
@ -521,9 +521,9 @@ AlterPublicationTables(AlterPublicationStmt *stmt, HeapTuple tup,
PUBLICATIONOBJ_TABLE); PUBLICATIONOBJ_TABLE);
PublicationAddTables(pubid, rels, false, stmt); PublicationAddTables(pubid, rels, false, stmt);
} }
else if (stmt->action == DEFELEM_DROP) else if (stmt->action == AP_DropObjects)
PublicationDropTables(pubid, rels, false); PublicationDropTables(pubid, rels, false);
else /* DEFELEM_SET */ else /* AP_SetObjects */
{ {
List *oldrelids = GetPublicationRelations(pubid, List *oldrelids = GetPublicationRelations(pubid,
PUBLICATION_PART_ROOT); PUBLICATION_PART_ROOT);
@ -598,7 +598,7 @@ AlterPublicationSchemas(AlterPublicationStmt *stmt,
* possible that user has not specified any schemas in which case we need * possible that user has not specified any schemas in which case we need
* to remove all the existing schemas. * to remove all the existing schemas.
*/ */
if (!schemaidlist && stmt->action != DEFELEM_SET) if (!schemaidlist && stmt->action != AP_SetObjects)
return; return;
/* /*
@ -606,7 +606,7 @@ AlterPublicationSchemas(AlterPublicationStmt *stmt,
* concurrent schema deletion. * concurrent schema deletion.
*/ */
LockSchemaList(schemaidlist); LockSchemaList(schemaidlist);
if (stmt->action == DEFELEM_ADD) if (stmt->action == AP_AddObjects)
{ {
List *rels; List *rels;
List *reloids; List *reloids;
@ -620,9 +620,9 @@ AlterPublicationSchemas(AlterPublicationStmt *stmt,
CloseTableList(rels); CloseTableList(rels);
PublicationAddSchemas(pubform->oid, schemaidlist, false, stmt); PublicationAddSchemas(pubform->oid, schemaidlist, false, stmt);
} }
else if (stmt->action == DEFELEM_DROP) else if (stmt->action == AP_DropObjects)
PublicationDropSchemas(pubform->oid, schemaidlist, false); PublicationDropSchemas(pubform->oid, schemaidlist, false);
else /* DEFELEM_SET */ else /* AP_SetObjects */
{ {
List *oldschemaids = GetPublicationSchemas(pubform->oid); List *oldschemaids = GetPublicationSchemas(pubform->oid);
List *delschemas = NIL; List *delschemas = NIL;
@ -657,7 +657,7 @@ CheckAlterPublication(AlterPublicationStmt *stmt, HeapTuple tup,
{ {
Form_pg_publication pubform = (Form_pg_publication) GETSTRUCT(tup); Form_pg_publication pubform = (Form_pg_publication) GETSTRUCT(tup);
if ((stmt->action == DEFELEM_ADD || stmt->action == DEFELEM_SET) && if ((stmt->action == AP_AddObjects || stmt->action == AP_SetObjects) &&
schemaidlist && !superuser()) schemaidlist && !superuser())
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),

View File

@ -9828,7 +9828,7 @@ AlterPublicationStmt:
n->pubname = $3; n->pubname = $3;
n->pubobjects = $5; n->pubobjects = $5;
preprocess_pubobj_list(n->pubobjects, yyscanner); preprocess_pubobj_list(n->pubobjects, yyscanner);
n->action = DEFELEM_ADD; n->action = AP_AddObjects;
$$ = (Node *)n; $$ = (Node *)n;
} }
| ALTER PUBLICATION name SET pub_obj_list | ALTER PUBLICATION name SET pub_obj_list
@ -9837,7 +9837,7 @@ AlterPublicationStmt:
n->pubname = $3; n->pubname = $3;
n->pubobjects = $5; n->pubobjects = $5;
preprocess_pubobj_list(n->pubobjects, yyscanner); preprocess_pubobj_list(n->pubobjects, yyscanner);
n->action = DEFELEM_SET; n->action = AP_SetObjects;
$$ = (Node *)n; $$ = (Node *)n;
} }
| ALTER PUBLICATION name DROP pub_obj_list | ALTER PUBLICATION name DROP pub_obj_list
@ -9846,7 +9846,7 @@ AlterPublicationStmt:
n->pubname = $3; n->pubname = $3;
n->pubobjects = $5; n->pubobjects = $5;
preprocess_pubobj_list(n->pubobjects, yyscanner); preprocess_pubobj_list(n->pubobjects, yyscanner);
n->action = DEFELEM_DROP; n->action = AP_DropObjects;
$$ = (Node *)n; $$ = (Node *)n;
} }
; ;

View File

@ -3674,6 +3674,13 @@ typedef struct CreatePublicationStmt
bool for_all_tables; /* Special publication for all tables in db */ bool for_all_tables; /* Special publication for all tables in db */
} CreatePublicationStmt; } CreatePublicationStmt;
typedef enum AlterPublicationAction
{
AP_AddObjects, /* add objects to publication */
AP_DropObjects, /* remove objects from publication */
AP_SetObjects /* set list of objects */
} AlterPublicationAction;
typedef struct AlterPublicationStmt typedef struct AlterPublicationStmt
{ {
NodeTag type; NodeTag type;
@ -3688,8 +3695,8 @@ typedef struct AlterPublicationStmt
*/ */
List *pubobjects; /* Optional list of publication objects */ List *pubobjects; /* Optional list of publication objects */
bool for_all_tables; /* Special publication for all tables in db */ bool for_all_tables; /* Special publication for all tables in db */
DefElemAction action; /* What action to perform with the AlterPublicationAction action; /* What action to perform with the given
* tables/schemas */ * objects */
} AlterPublicationStmt; } AlterPublicationStmt;
typedef struct CreateSubscriptionStmt typedef struct CreateSubscriptionStmt