Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9623d89

Browse files
committed
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
1 parent 234ba62 commit 9623d89

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

src/backend/commands/publicationcmds.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -503,12 +503,12 @@ AlterPublicationTables(AlterPublicationStmt *stmt, HeapTuple tup,
503503
* possible that user has not specified any tables in which case we need
504504
* to remove all the existing tables.
505505
*/
506-
if (!tables && stmt->action != DEFELEM_SET)
506+
if (!tables && stmt->action != AP_SetObjects)
507507
return;
508508

509509
rels = OpenTableList(tables);
510510

511-
if (stmt->action == DEFELEM_ADD)
511+
if (stmt->action == AP_AddObjects)
512512
{
513513
List *schemas = NIL;
514514

@@ -521,9 +521,9 @@ AlterPublicationTables(AlterPublicationStmt *stmt, HeapTuple tup,
521521
PUBLICATIONOBJ_TABLE);
522522
PublicationAddTables(pubid, rels, false, stmt);
523523
}
524-
else if (stmt->action == DEFELEM_DROP)
524+
else if (stmt->action == AP_DropObjects)
525525
PublicationDropTables(pubid, rels, false);
526-
else /* DEFELEM_SET */
526+
else /* AP_SetObjects */
527527
{
528528
List *oldrelids = GetPublicationRelations(pubid,
529529
PUBLICATION_PART_ROOT);
@@ -598,15 +598,15 @@ AlterPublicationSchemas(AlterPublicationStmt *stmt,
598598
* possible that user has not specified any schemas in which case we need
599599
* to remove all the existing schemas.
600600
*/
601-
if (!schemaidlist && stmt->action != DEFELEM_SET)
601+
if (!schemaidlist && stmt->action != AP_SetObjects)
602602
return;
603603

604604
/*
605605
* Schema lock is held until the publication is altered to prevent
606606
* concurrent schema deletion.
607607
*/
608608
LockSchemaList(schemaidlist);
609-
if (stmt->action == DEFELEM_ADD)
609+
if (stmt->action == AP_AddObjects)
610610
{
611611
List *rels;
612612
List *reloids;
@@ -620,9 +620,9 @@ AlterPublicationSchemas(AlterPublicationStmt *stmt,
620620
CloseTableList(rels);
621621
PublicationAddSchemas(pubform->oid, schemaidlist, false, stmt);
622622
}
623-
else if (stmt->action == DEFELEM_DROP)
623+
else if (stmt->action == AP_DropObjects)
624624
PublicationDropSchemas(pubform->oid, schemaidlist, false);
625-
else /* DEFELEM_SET */
625+
else /* AP_SetObjects */
626626
{
627627
List *oldschemaids = GetPublicationSchemas(pubform->oid);
628628
List *delschemas = NIL;
@@ -657,7 +657,7 @@ CheckAlterPublication(AlterPublicationStmt *stmt, HeapTuple tup,
657657
{
658658
Form_pg_publication pubform = (Form_pg_publication) GETSTRUCT(tup);
659659

660-
if ((stmt->action == DEFELEM_ADD || stmt->action == DEFELEM_SET) &&
660+
if ((stmt->action == AP_AddObjects || stmt->action == AP_SetObjects) &&
661661
schemaidlist && !superuser())
662662
ereport(ERROR,
663663
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),

src/backend/parser/gram.y

+3-3
Original file line numberDiff line numberDiff line change
@@ -9828,7 +9828,7 @@ AlterPublicationStmt:
98289828
n->pubname = $3;
98299829
n->pubobjects = $5;
98309830
preprocess_pubobj_list(n->pubobjects, yyscanner);
9831-
n->action = DEFELEM_ADD;
9831+
n->action = AP_AddObjects;
98329832
$$ = (Node *)n;
98339833
}
98349834
| ALTER PUBLICATION name SET pub_obj_list
@@ -9837,7 +9837,7 @@ AlterPublicationStmt:
98379837
n->pubname = $3;
98389838
n->pubobjects = $5;
98399839
preprocess_pubobj_list(n->pubobjects, yyscanner);
9840-
n->action = DEFELEM_SET;
9840+
n->action = AP_SetObjects;
98419841
$$ = (Node *)n;
98429842
}
98439843
| ALTER PUBLICATION name DROP pub_obj_list
@@ -9846,7 +9846,7 @@ AlterPublicationStmt:
98469846
n->pubname = $3;
98479847
n->pubobjects = $5;
98489848
preprocess_pubobj_list(n->pubobjects, yyscanner);
9849-
n->action = DEFELEM_DROP;
9849+
n->action = AP_DropObjects;
98509850
$$ = (Node *)n;
98519851
}
98529852
;

src/include/nodes/parsenodes.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -3674,6 +3674,13 @@ typedef struct CreatePublicationStmt
36743674
bool for_all_tables; /* Special publication for all tables in db */
36753675
} CreatePublicationStmt;
36763676

3677+
typedef enum AlterPublicationAction
3678+
{
3679+
AP_AddObjects, /* add objects to publication */
3680+
AP_DropObjects, /* remove objects from publication */
3681+
AP_SetObjects /* set list of objects */
3682+
} AlterPublicationAction;
3683+
36773684
typedef struct AlterPublicationStmt
36783685
{
36793686
NodeTag type;
@@ -3688,8 +3695,8 @@ typedef struct AlterPublicationStmt
36883695
*/
36893696
List *pubobjects; /* Optional list of publication objects */
36903697
bool for_all_tables; /* Special publication for all tables in db */
3691-
DefElemAction action; /* What action to perform with the
3692-
* tables/schemas */
3698+
AlterPublicationAction action; /* What action to perform with the given
3699+
* objects */
36933700
} AlterPublicationStmt;
36943701

36953702
typedef struct CreateSubscriptionStmt

0 commit comments

Comments
 (0)