Skip to content

Commit 6e94901

Browse files
committed
Support ALTER GROUP ... ADD/DROP USER
1 parent ae6027f commit 6e94901

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

src/cst/AlterAction.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ export type AlterRoleAction =
153153
| AlterActionRename
154154
| AlterActionSetPostgresqlOption
155155
| AlterActionSetPostgresqlOptionFromCurrent
156-
| AlterActionResetPostgresqlOption;
156+
| AlterActionResetPostgresqlOption
157+
| AlterActionAddUser
158+
| AlterActionDropUser;
157159

158160
export interface AlterActionRename extends BaseNode {
159161
type: "alter_action_rename";
@@ -541,6 +543,20 @@ export interface AlterActionWithRoleOptions extends BaseNode {
541543
options: RoleOption[];
542544
}
543545

546+
// PostgreSQL
547+
export interface AlterActionAddUser extends BaseNode {
548+
type: "alter_action_add_user";
549+
addUserKw: [Keyword<"ADD">, Keyword<"USER">];
550+
users: ListExpr<Identifier>;
551+
}
552+
553+
// PostgreSQL
554+
export interface AlterActionDropUser extends BaseNode {
555+
type: "alter_action_drop_user";
556+
dropUserKw: [Keyword<"DROP">, Keyword<"USER">];
557+
users: ListExpr<Identifier>;
558+
}
559+
544560
export type AlterColumnAction =
545561
| AlterActionSetDefault
546562
| AlterActionDropDefault

src/parser.pegjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4480,6 +4480,8 @@ alter_role_action
44804480
/ alter_action_set_postgresql_option
44814481
/ alter_action_set_postgresql_option_from_current
44824482
/ alter_action_reset_postgresql_option
4483+
/ alter_action_add_user
4484+
/ alter_action_drop_user
44834485

44844486
alter_action_with_role_options
44854487
= kw:WITH options:(__ role_option)+ {
@@ -4526,6 +4528,24 @@ alter_action_reset_postgresql_option
45264528
});
45274529
}
45284530

4531+
alter_action_add_user
4532+
= kw:(ADD __ USER __) users:list$ident {
4533+
return loc({
4534+
type: "alter_action_add_user",
4535+
addUserKw: read(kw),
4536+
users,
4537+
});
4538+
}
4539+
4540+
alter_action_drop_user
4541+
= kw:(DROP __ USER __) users:list$ident {
4542+
return loc({
4543+
type: "alter_action_drop_user",
4544+
dropUserKw: read(kw),
4545+
users,
4546+
});
4547+
}
4548+
45294549
drop_role_stmt
45304550
= kw:(DROP __ (ROLE / USER / GROUP) __) ifExistsKw:(if_exists __)? names:list$role_specification {
45314551
return loc({

src/showNode/alter_action.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ export const alterActionMap: FullTransformMap<string, AllAlterActionNodes> = {
106106
node.constraint,
107107
node.behaviorKw,
108108
]),
109+
alter_action_add_user: (node) => show([node.addUserKw, node.users]),
110+
alter_action_drop_user: (node) => show([node.dropUserKw, node.users]),
109111

110112
// ALTER COLUMN ...
111113
alter_action_alter_column: (node) =>

test/ddl/role.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ describe("role", () => {
163163
testWc("ALTER GROUP my_user RENAME TO new_user");
164164
testWc(`ALTER GROUP ALL IN DATABASE foo SET something TO 128`);
165165
});
166+
167+
it("supports ADD USER", () => {
168+
testWc("ALTER GROUP moderator ADD USER mary, john");
169+
});
170+
171+
it("supports DROP USER", () => {
172+
testWc("ALTER GROUP moderator DROP USER mary, john");
173+
});
166174
});
167175

168176
describe("DROP GROUP", () => {

0 commit comments

Comments
 (0)