Avoid using DefElemAction in AlterPublicationStmt
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 3 Jan 2022 13:48:48 +0000 (10:48 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 3 Jan 2022 13:48:48 +0000 (10:48 -0300)
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

src/backend/commands/publicationcmds.c
src/backend/parser/gram.y
src/include/nodes/parsenodes.h

index f932f47a08615f954a83efde3ec80f615cd471ce..0f04969fd6c8da5ca1a7b806ef4a433a451f63f2 100644 (file)
@@ -503,12 +503,12 @@ AlterPublicationTables(AlterPublicationStmt *stmt, HeapTuple tup,
     * possible that user has not specified any tables in which case we need
     * to remove all the existing tables.
     */
-   if (!tables && stmt->action != DEFELEM_SET)
+   if (!tables && stmt->action != AP_SetObjects)
        return;
 
    rels = OpenTableList(tables);
 
-   if (stmt->action == DEFELEM_ADD)
+   if (stmt->action == AP_AddObjects)
    {
        List       *schemas = NIL;
 
@@ -521,9 +521,9 @@ AlterPublicationTables(AlterPublicationStmt *stmt, HeapTuple tup,
                                              PUBLICATIONOBJ_TABLE);
        PublicationAddTables(pubid, rels, false, stmt);
    }
-   else if (stmt->action == DEFELEM_DROP)
+   else if (stmt->action == AP_DropObjects)
        PublicationDropTables(pubid, rels, false);
-   else                        /* DEFELEM_SET */
+   else                        /* AP_SetObjects */
    {
        List       *oldrelids = GetPublicationRelations(pubid,
                                                        PUBLICATION_PART_ROOT);
@@ -598,7 +598,7 @@ AlterPublicationSchemas(AlterPublicationStmt *stmt,
     * possible that user has not specified any schemas in which case we need
     * to remove all the existing schemas.
     */
-   if (!schemaidlist && stmt->action != DEFELEM_SET)
+   if (!schemaidlist && stmt->action != AP_SetObjects)
        return;
 
    /*
@@ -606,7 +606,7 @@ AlterPublicationSchemas(AlterPublicationStmt *stmt,
     * concurrent schema deletion.
     */
    LockSchemaList(schemaidlist);
-   if (stmt->action == DEFELEM_ADD)
+   if (stmt->action == AP_AddObjects)
    {
        List       *rels;
        List       *reloids;
@@ -620,9 +620,9 @@ AlterPublicationSchemas(AlterPublicationStmt *stmt,
        CloseTableList(rels);
        PublicationAddSchemas(pubform->oid, schemaidlist, false, stmt);
    }
-   else if (stmt->action == DEFELEM_DROP)
+   else if (stmt->action == AP_DropObjects)
        PublicationDropSchemas(pubform->oid, schemaidlist, false);
-   else                        /* DEFELEM_SET */
+   else                        /* AP_SetObjects */
    {
        List       *oldschemaids = GetPublicationSchemas(pubform->oid);
        List       *delschemas = NIL;
@@ -657,7 +657,7 @@ CheckAlterPublication(AlterPublicationStmt *stmt, HeapTuple 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())
        ereport(ERROR,
                (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
index f3c232842d66d23a71f00a5fac6e1ff64812e362..6dddc079474b27418a879266f432214b6dce7f5d 100644 (file)
@@ -9828,7 +9828,7 @@ AlterPublicationStmt:
                    n->pubname = $3;
                    n->pubobjects = $5;
                    preprocess_pubobj_list(n->pubobjects, yyscanner);
-                   n->action = DEFELEM_ADD;
+                   n->action = AP_AddObjects;
                    $$ = (Node *)n;
                }
            | ALTER PUBLICATION name SET pub_obj_list
@@ -9837,7 +9837,7 @@ AlterPublicationStmt:
                    n->pubname = $3;
                    n->pubobjects = $5;
                    preprocess_pubobj_list(n->pubobjects, yyscanner);
-                   n->action = DEFELEM_SET;
+                   n->action = AP_SetObjects;
                    $$ = (Node *)n;
                }
            | ALTER PUBLICATION name DROP pub_obj_list
@@ -9846,7 +9846,7 @@ AlterPublicationStmt:
                    n->pubname = $3;
                    n->pubobjects = $5;
                    preprocess_pubobj_list(n->pubobjects, yyscanner);
-                   n->action = DEFELEM_DROP;
+                   n->action = AP_DropObjects;
                    $$ = (Node *)n;
                }
        ;
index 784164b32aaf0f31f3b84fff7d2efe7b84c536f8..593e301f7a2c35fc9e5814db4ded9afdc4eafd5f 100644 (file)
@@ -3674,6 +3674,13 @@ typedef struct CreatePublicationStmt
    bool        for_all_tables; /* Special publication for all tables in db */
 } 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
 {
    NodeTag     type;
@@ -3688,8 +3695,8 @@ typedef struct AlterPublicationStmt
     */
    List       *pubobjects;     /* Optional list of publication objects */
    bool        for_all_tables; /* Special publication for all tables in db */
-   DefElemAction action;       /* What action to perform with the
-                                * tables/schemas */
+   AlterPublicationAction action;  /* What action to perform with the given
+                                    * objects */
 } AlterPublicationStmt;
 
 typedef struct CreateSubscriptionStmt