diff --git a/ast/misc.go b/ast/misc.go index d69a22360..e0805955a 100755 --- a/ast/misc.go +++ b/ast/misc.go @@ -887,13 +887,18 @@ func (n *AlterUserStmt) Accept(v Visitor) (Node, bool) { type DropUserStmt struct { stmtNode - IfExists bool - UserList []*auth.UserIdentity + IfExists bool + IsDropRole bool + UserList []*auth.UserIdentity } // Restore implements Node interface. func (n *DropUserStmt) Restore(ctx *RestoreCtx) error { - ctx.WriteKeyWord("DROP USER ") + if n.IsDropRole { + ctx.WriteKeyWord("DROP ROLE ") + } else { + ctx.WriteKeyWord("DROP USER ") + } if n.IfExists { ctx.WriteKeyWord("IF EXISTS ") } diff --git a/mysql/const.go b/mysql/const.go index ea0216869..334f047eb 100644 --- a/mysql/const.go +++ b/mysql/const.go @@ -182,6 +182,10 @@ const ( GlobalStatusTable = "GLOBAL_STATUS" // TiDBTable is the table contains tidb info. TiDBTable = "tidb" + // RoleEdgesTable is the table contains role relation info + RoleEdgeTable = "role_edges" + // DefaultRoleTable is the table contain default active role info + DefaultRoleTable = "default_roles" ) // PrivilegeType privilege diff --git a/parser.go b/parser.go index 794cd11eb..d86a67337 100644 --- a/parser.go +++ b/parser.go @@ -8438,11 +8438,29 @@ yynewstate: } case 233: { - parser.yyVAL.statement = &ast.DropUserStmt{IfExists: false, UserList: yyS[yypt-0].item.([]*auth.UserIdentity)} + parser.yyVAL.statement = &ast.DropUserStmt{IsDropRole: false, IfExists: false, UserList: yyS[yypt-0].item.([]*auth.UserIdentity)} } case 234: { - parser.yyVAL.statement = &ast.DropUserStmt{IfExists: true, UserList: yyS[yypt-0].item.([]*auth.UserIdentity)} + parser.yyVAL.statement = &ast.DropUserStmt{IsDropRole: false, IfExists: true, UserList: yyS[yypt-0].item.([]*auth.UserIdentity)} + } + case 235: + { + tmp := make([]*auth.UserIdentity, 0, 10) + roleList := yyS[yypt-0].item.([]*auth.RoleIdentity) + for _, r := range roleList { + tmp = append(tmp, &auth.UserIdentity{Username: r.Username, Hostname: r.Hostname}) + } + parser.yyVAL.statement = &ast.DropUserStmt{IsDropRole: true, IfExists: false, UserList: tmp} + } + case 236: + { + tmp := make([]*auth.UserIdentity, 0, 10) + roleList := yyS[yypt-0].item.([]*auth.RoleIdentity) + for _, r := range roleList { + tmp = append(tmp, &auth.UserIdentity{Username: r.Username, Hostname: r.Hostname}) + } + parser.yyVAL.statement = &ast.DropUserStmt{IsDropRole: true, IfExists: true, UserList: tmp} } case 237: { diff --git a/parser.y b/parser.y index 960dbd05d..f74628151 100644 --- a/parser.y +++ b/parser.y @@ -2429,19 +2429,31 @@ DropViewStmt: DropUserStmt: "DROP" "USER" UsernameList { - $$ = &ast.DropUserStmt{IfExists: false, UserList: $3.([]*auth.UserIdentity)} + $$ = &ast.DropUserStmt{IsDropRole: false, IfExists: false, UserList: $3.([]*auth.UserIdentity)} } | "DROP" "USER" "IF" "EXISTS" UsernameList { - $$ = &ast.DropUserStmt{IfExists: true, UserList: $5.([]*auth.UserIdentity)} + $$ = &ast.DropUserStmt{IsDropRole: false, IfExists: true, UserList: $5.([]*auth.UserIdentity)} } DropRoleStmt: "DROP" "ROLE" RolenameList { + tmp := make([]*auth.UserIdentity, 0, 10) + roleList := $3.([]*auth.RoleIdentity) + for _, r := range roleList { + tmp = append(tmp, &auth.UserIdentity{Username:r.Username, Hostname: r.Hostname}) + } + $$ = &ast.DropUserStmt{IsDropRole: true, IfExists: false, UserList: tmp} } | "DROP" "ROLE" "IF" "EXISTS" RolenameList { + tmp := make([]*auth.UserIdentity, 0, 10) + roleList := $5.([]*auth.RoleIdentity) + for _, r := range roleList { + tmp = append(tmp, &auth.UserIdentity{Username:r.Username, Hostname: r.Hostname}) + } + $$ = &ast.DropUserStmt{IsDropRole: true, IfExists: true, UserList: tmp} } DropStatsStmt: