Skip to content

Commit 2cbc098

Browse files
authored
support privileges for routines and sequences (#2384)
* support privileges for routines and sequences * update TestRevoke * update grant tests * add auth to create routines and sequence statements * update gms * format * find uses of sequences to check authorization * check for sequences in functions * format * update serialization * fix parsing for aggregate sfunc
1 parent a989909 commit 2cbc098

32 files changed

Lines changed: 15808 additions & 14454 deletions

postgres/parser/parser/sql.y

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4070,10 +4070,10 @@ create_aggregate_stmt:
40704070
| create_aggregate_old_syntax_stmt
40714071

40724072
create_aggregate_args_only_stmt:
4073-
CREATE AGGREGATE aggregate_name '(' opt_routine_args ')' '(' SFUNC '=' name ',' STYPE '=' type_name create_agg_args_only_option_list ')'
4074-
{ $$.val = &tree.CreateAggregate{Name: $3.unresolvedObjectName(), Args: $5.routineArgs(), SFunc: $10, SType: $14.typeReference(), AggOptions: $15.createAggOptions()} }
4075-
| CREATE OR REPLACE AGGREGATE aggregate_name '(' opt_routine_args ')' '(' SFUNC '=' name ',' STYPE '=' type_name create_agg_args_only_option_list ')'
4076-
{ $$.val = &tree.CreateAggregate{Name: $5.unresolvedObjectName(), Replace: true, Args: $7.routineArgs(), SFunc: $12, SType: $16.typeReference(), AggOptions: $17.createAggOptions()} }
4073+
CREATE AGGREGATE aggregate_name '(' opt_routine_args ')' '(' SFUNC '=' routine_name ',' STYPE '=' type_name create_agg_args_only_option_list ')'
4074+
{ $$.val = &tree.CreateAggregate{Name: $3.unresolvedObjectName(), Args: $5.routineArgs(), SFunc: $10.unresolvedObjectName(), SType: $14.typeReference(), AggOptions: $15.createAggOptions()} }
4075+
| CREATE OR REPLACE AGGREGATE aggregate_name '(' opt_routine_args ')' '(' SFUNC '=' routine_name ',' STYPE '=' type_name create_agg_args_only_option_list ')'
4076+
{ $$.val = &tree.CreateAggregate{Name: $5.unresolvedObjectName(), Replace: true, Args: $7.routineArgs(), SFunc: $12.unresolvedObjectName(), SType: $16.typeReference(), AggOptions: $17.createAggOptions()} }
40774077

40784078
create_agg_args_only_option_list:
40794079
/* EMPTY */
@@ -4088,10 +4088,10 @@ create_agg_args_only_option:
40884088
| create_agg_parallel_option
40894089

40904090
create_aggregate_order_by_args_stmt:
4091-
CREATE AGGREGATE aggregate_name '(' opt_routine_args ORDER BY routine_arg_list ')' '(' SFUNC '=' name ',' STYPE '=' type_name create_agg_order_by_args_option_list ')'
4092-
{ $$.val = &tree.CreateAggregate{Name: $3.unresolvedObjectName(), Args: $5.routineArgs(), OrderByArgs: $8.routineArgs(), SFunc: $13, SType: $17.typeReference(), AggOptions: $18.createAggOptions()} }
4093-
| CREATE OR REPLACE AGGREGATE aggregate_name '(' opt_routine_args ORDER BY routine_arg_list ')' '(' SFUNC '=' name ',' STYPE '=' type_name create_agg_order_by_args_option_list ')'
4094-
{ $$.val = &tree.CreateAggregate{Name: $5.unresolvedObjectName(), Replace: true, Args: $7.routineArgs(), OrderByArgs: $10.routineArgs(), SFunc: $15, SType: $19.typeReference(), AggOptions: $20.createAggOptions()} }
4091+
CREATE AGGREGATE aggregate_name '(' opt_routine_args ORDER BY routine_arg_list ')' '(' SFUNC '=' routine_name ',' STYPE '=' type_name create_agg_order_by_args_option_list ')'
4092+
{ $$.val = &tree.CreateAggregate{Name: $3.unresolvedObjectName(), Args: $5.routineArgs(), OrderByArgs: $8.routineArgs(), SFunc: $13.unresolvedObjectName(), SType: $17.typeReference(), AggOptions: $18.createAggOptions()} }
4093+
| CREATE OR REPLACE AGGREGATE aggregate_name '(' opt_routine_args ORDER BY routine_arg_list ')' '(' SFUNC '=' routine_name ',' STYPE '=' type_name create_agg_order_by_args_option_list ')'
4094+
{ $$.val = &tree.CreateAggregate{Name: $5.unresolvedObjectName(), Replace: true, Args: $7.routineArgs(), OrderByArgs: $10.routineArgs(), SFunc: $15.unresolvedObjectName(), SType: $19.typeReference(), AggOptions: $20.createAggOptions()} }
40954095

40964096
create_agg_order_by_args_option_list:
40974097
/* EMPTY */
@@ -4108,10 +4108,10 @@ create_agg_order_by_args_option:
41084108
{ $$.val = tree.CreateAggOption{Option: tree.AggOptTypeHypothetical} }
41094109

41104110
create_aggregate_old_syntax_stmt:
4111-
CREATE AGGREGATE aggregate_name '(' BASETYPE '=' type_name ',' SFUNC '=' name ',' STYPE '=' type_name create_agg_old_syntax_option_list ')'
4112-
{ $$.val = &tree.CreateAggregate{Name: $3.unresolvedObjectName(), BaseType: $7.typeReference(), SFunc: $11, SType: $15.typeReference(), AggOptions: $16.createAggOptions()} }
4113-
| CREATE OR REPLACE AGGREGATE aggregate_name '(' BASETYPE '=' type_name ',' SFUNC '=' name ',' STYPE '=' type_name create_agg_old_syntax_option_list ')'
4114-
{ $$.val = &tree.CreateAggregate{Name: $5.unresolvedObjectName(), Replace: true, BaseType: $9.typeReference(), SFunc: $13, SType: $17.typeReference(), AggOptions: $18.createAggOptions()} }
4111+
CREATE AGGREGATE aggregate_name '(' BASETYPE '=' type_name ',' SFUNC '=' routine_name ',' STYPE '=' type_name create_agg_old_syntax_option_list ')'
4112+
{ $$.val = &tree.CreateAggregate{Name: $3.unresolvedObjectName(), BaseType: $7.typeReference(), SFunc: $11.unresolvedObjectName(), SType: $15.typeReference(), AggOptions: $16.createAggOptions()} }
4113+
| CREATE OR REPLACE AGGREGATE aggregate_name '(' BASETYPE '=' type_name ',' SFUNC '=' routine_name ',' STYPE '=' type_name create_agg_old_syntax_option_list ')'
4114+
{ $$.val = &tree.CreateAggregate{Name: $5.unresolvedObjectName(), Replace: true, BaseType: $9.typeReference(), SFunc: $13.unresolvedObjectName(), SType: $17.typeReference(), AggOptions: $18.createAggOptions()} }
41154115

41164116
create_agg_old_syntax_option_list:
41174117
/* EMPTY */
@@ -4123,22 +4123,22 @@ create_agg_old_syntax_option_list:
41234123

41244124
create_agg_old_syntax_option:
41254125
create_agg_common_option
4126-
| COMBINEFUNC '=' name
4127-
{ $$.val = tree.CreateAggOption{Option: tree.AggOptTypeCombineFunc, StrVal: $3} }
4128-
| SERIALFUNC '=' name
4129-
{ $$.val = tree.CreateAggOption{Option: tree.AggOptTypeSerialFunc, StrVal: $3} }
4130-
| DESERIALFUNC '=' name
4131-
{ $$.val = tree.CreateAggOption{Option: tree.AggOptTypeDeserialFunc, StrVal: $3} }
4132-
| MSFUNC '=' name
4133-
{ $$.val = tree.CreateAggOption{Option: tree.AggOptTypeMSFunc, StrVal: $3} }
4134-
| MINVFUNC '=' name
4135-
{ $$.val = tree.CreateAggOption{Option: tree.AggOptTypeMInvFunc, StrVal: $3} }
4126+
| COMBINEFUNC '=' routine_name
4127+
{ $$.val = tree.CreateAggOption{Option: tree.AggOptTypeCombineFunc, FuncName: $3.unresolvedObjectName()} }
4128+
| SERIALFUNC '=' routine_name
4129+
{ $$.val = tree.CreateAggOption{Option: tree.AggOptTypeSerialFunc, FuncName: $3.unresolvedObjectName()} }
4130+
| DESERIALFUNC '=' routine_name
4131+
{ $$.val = tree.CreateAggOption{Option: tree.AggOptTypeDeserialFunc, FuncName: $3.unresolvedObjectName()} }
4132+
| MSFUNC '=' routine_name
4133+
{ $$.val = tree.CreateAggOption{Option: tree.AggOptTypeMSFunc, FuncName: $3.unresolvedObjectName()} }
4134+
| MINVFUNC '=' routine_name
4135+
{ $$.val = tree.CreateAggOption{Option: tree.AggOptTypeMInvFunc, FuncName: $3.unresolvedObjectName()} }
41364136
| MSTYPE '=' type_name
41374137
{ $$.val = tree.CreateAggOption{Option: tree.AggOptTypeMSType, TypeVal: $3.typeReference()} }
41384138
| MSSPACE '=' iconst64
41394139
{ $$.val = tree.CreateAggOption{Option: tree.AggOptTypeMSSpace, IntVal: $3.expr()} }
4140-
| MFINALFUNC '=' name
4141-
{ $$.val = tree.CreateAggOption{Option: tree.AggOptTypeMFinalFunc, StrVal: $3} }
4140+
| MFINALFUNC '=' routine_name
4141+
{ $$.val = tree.CreateAggOption{Option: tree.AggOptTypeMFinalFunc, FuncName: $3.unresolvedObjectName()} }
41424142
| MFINALFUNC_EXTRA '=' TRUE
41434143
{ $$.val = tree.CreateAggOption{Option: tree.AggOptTypeMFinalFuncExtra, BoolVal: true} }
41444144
| MFINALFUNC_EXTRA '=' FALSE
@@ -4157,8 +4157,8 @@ create_agg_old_syntax_option:
41574157
create_agg_common_option:
41584158
SSPACE '=' iconst64
41594159
{ $$.val = tree.CreateAggOption{Option: tree.AggOptTypeSSpace, IntVal: $3.expr()} }
4160-
| FINALFUNC '=' name
4161-
{ $$.val = tree.CreateAggOption{Option: tree.AggOptTypeFinalFunc, StrVal: $3} }
4160+
| FINALFUNC '=' routine_name
4161+
{ $$.val = tree.CreateAggOption{Option: tree.AggOptTypeFinalFunc, FuncName: $3.unresolvedObjectName()} }
41624162
| FINALFUNC_EXTRA '=' TRUE
41634163
{ $$.val = tree.CreateAggOption{Option: tree.AggOptTypeFinalFuncExtra, BoolVal: true} }
41644164
| FINALFUNC_EXTRA '=' FALSE

postgres/parser/sem/tree/create_aggregate.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type CreateAggregate struct {
2323
Name *UnresolvedObjectName
2424
Replace bool
2525
Args RoutineArgs
26-
SFunc string
26+
SFunc *UnresolvedObjectName
2727
SType ResolvableTypeReference
2828
AggOptions CreateAggOptions
2929
OrderByArgs RoutineArgs
@@ -55,7 +55,7 @@ func (node *CreateAggregate) Format(ctx *FmtCtx) {
5555
ctx.WriteString(" , ")
5656
}
5757
ctx.WriteString("SFUNC = ")
58-
ctx.WriteString(node.SFunc)
58+
ctx.FormatNode(node.SFunc)
5959
ctx.WriteString(" , STYPE = ")
6060
ctx.WriteString(node.BaseType.SQLString())
6161
if node.AggOptions != nil {
@@ -91,7 +91,7 @@ type CreateAggOption struct {
9191
BoolVal bool
9292
// StrVal is used for FinalFunc, CombineFunc, SerialFunc,
9393
// DeserialFunc, MSFunc, MInvFunc and MFinalFunc
94-
StrVal string
94+
FuncName *UnresolvedObjectName
9595
// FinalFuncModify is used for FinalFuncModify and MFinalFuncModify
9696
FinalFuncModify FinalFuncModifyType
9797
// TypeVal is used for MSType
@@ -109,7 +109,7 @@ func (node *CreateAggOption) Format(ctx *FmtCtx) {
109109
ctx.FormatNode(node.IntVal)
110110
case AggOptTypeFinalFunc:
111111
ctx.WriteString("FINALFUNC = ")
112-
ctx.WriteString(node.StrVal)
112+
ctx.FormatNode(node.FuncName)
113113
case AggOptTypeFinalFuncExtra:
114114
if node.BoolVal {
115115
ctx.WriteString("FINALFUNC_EXTRA = TRUE")
@@ -121,22 +121,22 @@ func (node *CreateAggOption) Format(ctx *FmtCtx) {
121121
ctx.WriteString(string(node.FinalFuncModify))
122122
case AggOptTypeCombineFunc:
123123
ctx.WriteString("COMBINEFUNC = ")
124-
ctx.WriteString(node.StrVal)
124+
ctx.FormatNode(node.FuncName)
125125
case AggOptTypeSerialFunc:
126126
ctx.WriteString("SERIALFUNC = ")
127-
ctx.WriteString(node.StrVal)
127+
ctx.FormatNode(node.FuncName)
128128
case AggOptTypeDeserialFunc:
129129
ctx.WriteString("DESERIALFUNC = ")
130-
ctx.WriteString(node.StrVal)
130+
ctx.FormatNode(node.FuncName)
131131
case AggOptTypeInitCond:
132132
ctx.WriteString("INITCOND = ")
133133
ctx.FormatNode(node.CondVal)
134134
case AggOptTypeMSFunc:
135135
ctx.WriteString("MSFUNC = ")
136-
ctx.WriteString(node.StrVal)
136+
ctx.FormatNode(node.FuncName)
137137
case AggOptTypeMInvFunc:
138138
ctx.WriteString("MINVFUNC = ")
139-
ctx.WriteString(node.StrVal)
139+
ctx.FormatNode(node.FuncName)
140140
case AggOptTypeMSType:
141141
ctx.WriteString("MSTYPE = ")
142142
ctx.WriteString(node.TypeVal.SQLString())
@@ -145,7 +145,7 @@ func (node *CreateAggOption) Format(ctx *FmtCtx) {
145145
ctx.FormatNode(node.IntVal)
146146
case AggOptTypeMFinalFunc:
147147
ctx.WriteString("MFINALFUNC = ")
148-
ctx.WriteString(node.StrVal)
148+
ctx.FormatNode(node.FuncName)
149149
case AggOptTypeMFinalFuncExtra:
150150
if node.BoolVal {
151151
ctx.WriteString("MFINALFUNC_EXTRA = TRUE")

server/analyzer/optimize_functions.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ func OptimizeFunctions(ctx *sql.Context, a *analyzer.Analyzer, node sql.Node, sc
4646
// Check if there is set returning function in the source node (e.g. SELECT * FROM unnest())
4747
n, sameNode, err := transform.NodeExprsWithNode(projectNode.Child, func(in sql.Node, expr sql.Expression) (sql.Expression, transform.TreeIdentity, error) {
4848
if compiledFunction, ok := expr.(*framework.CompiledFunction); ok {
49+
// TODO: need better way to detect sequence usage
50+
switch compiledFunction.FunctionName() {
51+
case "nextval", "setval", "currval":
52+
err := authCheckSequenceFromExpr(ctx, a.Catalog.AuthHandler, compiledFunction.Arguments[0])
53+
if err != nil {
54+
return nil, transform.SameTree, err
55+
}
56+
}
4957
hasSRF = hasSRF || compiledFunction.IsSRF()
5058
if quickFunction := compiledFunction.GetQuickFunction(); quickFunction != nil {
5159
return quickFunction, transform.NewTree, nil
@@ -76,6 +84,14 @@ func OptimizeFunctions(ctx *sql.Context, a *analyzer.Analyzer, node sql.Node, sc
7684
if quickFunction := compiledFunction.GetQuickFunction(); quickFunction != nil {
7785
return quickFunction, transform.NewTree, nil
7886
}
87+
// TODO: need better way to detect sequence usage
88+
switch compiledFunction.FunctionName() {
89+
case "nextval", "setval", "currval":
90+
err = authCheckSequenceFromExpr(ctx, a.Catalog.AuthHandler, compiledFunction.Arguments[0])
91+
if err != nil {
92+
return nil, transform.SameTree, err
93+
}
94+
}
7995
}
8096
return expr, transform.SameTree, nil
8197
})

server/analyzer/serial.go

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@ import (
2525
"github.com/dolthub/go-mysql-server/sql/expression"
2626
"github.com/dolthub/go-mysql-server/sql/plan"
2727
"github.com/dolthub/go-mysql-server/sql/transform"
28+
"github.com/dolthub/vitess/go/vt/sqlparser"
2829

2930
"github.com/dolthub/doltgresql/core"
3031
"github.com/dolthub/doltgresql/core/id"
3132
"github.com/dolthub/doltgresql/core/sequences"
3233
"github.com/dolthub/doltgresql/server/ast"
34+
"github.com/dolthub/doltgresql/server/auth"
3335
pgexprs "github.com/dolthub/doltgresql/server/expression"
36+
"github.com/dolthub/doltgresql/server/functions"
3437
"github.com/dolthub/doltgresql/server/functions/framework"
3538
pgnodes "github.com/dolthub/doltgresql/server/node"
3639
pgtypes "github.com/dolthub/doltgresql/server/types"
@@ -63,14 +66,14 @@ func ReplaceSerial(ctx *sql.Context, a *analyzer.Analyzer, node sql.Node, scope
6366
if col.Generated != nil {
6467
seenNextVal := false
6568
transform.InspectExpr(col.Generated, func(expr sql.Expression) bool {
66-
switch expr := expr.(type) {
69+
switch e := expr.(type) {
6770
case *framework.CompiledFunction:
68-
if strings.ToLower(expr.Name) == "nextval" {
71+
if strings.ToLower(e.Name) == "nextval" {
6972
seenNextVal = true
7073
}
7174
case *expression.Literal:
7275
placeholderName := fmt.Sprintf("'%s'", ast.DoltCreateTablePlaceholderSequenceName)
73-
if expr.String() == placeholderName {
76+
if e.String() == placeholderName {
7477
isGeneratedFromSequence = true
7578
}
7679
}
@@ -92,6 +95,12 @@ func ReplaceSerial(ctx *sql.Context, a *analyzer.Analyzer, node sql.Node, scope
9295
return nil, transform.NewTree, err
9396
}
9497

98+
// TODO: need better way to detect sequence usage
99+
err = authCheckSequence(ctx, a.Catalog.AuthHandler, schemaName, sequenceName)
100+
if err != nil {
101+
return nil, transform.SameTree, err
102+
}
103+
95104
seqName := doltdb.TableName{Name: sequenceName, Schema: schemaName}.String()
96105
nextVal, isDoltgresType, err := framework.GetFunction("nextval", pgexprs.NewTextLiteral(seqName))
97106
if err != nil {
@@ -173,3 +182,28 @@ func generateSequenceName(ctx *sql.Context, createTable *plan.CreateTable, col *
173182
}
174183
return sequenceName, nil
175184
}
185+
186+
// authCheckSequenceFromExpr checks authorization of sequence being used.
187+
// It parses schema and sequence names out of given expression.
188+
// There can be only one argument expression of string type.
189+
func authCheckSequenceFromExpr(ctx *sql.Context, ah sql.AuthorizationHandler, arg sql.Expression) error {
190+
schemaName, seqName, err := functions.ParseRelationName(ctx, strings.Trim(arg.String(), "'"))
191+
if err != nil {
192+
return err
193+
}
194+
195+
return authCheckSequence(ctx, ah, schemaName, seqName)
196+
}
197+
198+
// authCheckSequence checks authorization of sequence being used. We cannot check it during parsing because we cannot
199+
// detect sequence currently, so we try to catch any sequence being used and check authorization here.
200+
func authCheckSequence(ctx *sql.Context, ah sql.AuthorizationHandler, schemaName, seqName string) error {
201+
if err := ah.HandleAuth(ctx, ah.NewQueryState(ctx), sqlparser.AuthInformation{
202+
AuthType: auth.AuthType_USAGE,
203+
TargetType: auth.AuthTargetType_SequenceIdentifiers,
204+
TargetNames: []string{schemaName, seqName},
205+
}); err != nil {
206+
return err
207+
}
208+
return nil
209+
}

server/ast/alter_sequence.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
vitess "github.com/dolthub/vitess/go/vt/sqlparser"
2222

2323
"github.com/dolthub/doltgresql/postgres/parser/sem/tree"
24+
"github.com/dolthub/doltgresql/server/auth"
2425
pgnodes "github.com/dolthub/doltgresql/server/node"
2526
)
2627

@@ -92,5 +93,10 @@ func nodeAlterSequence(ctx *Context, node *tree.AlterSequence) (vitess.Statement
9293
ownedBy,
9394
warnings...),
9495
Children: nil,
96+
Auth: vitess.AuthInformation{
97+
AuthType: auth.AuthType_UPDATE,
98+
TargetType: auth.AuthTargetType_SequenceIdentifiers,
99+
TargetNames: []string{name.SchemaQualifier.String(), name.Name.String()},
100+
},
95101
}, nil
96102
}

server/ast/call.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ package ast
1616

1717
import (
1818
"github.com/cockroachdb/errors"
19-
2019
vitess "github.com/dolthub/vitess/go/vt/sqlparser"
2120

21+
"github.com/dolthub/doltgresql/server/auth"
22+
2223
"github.com/dolthub/doltgresql/postgres/parser/sem/tree"
2324
pgnodes "github.com/dolthub/doltgresql/server/node"
2425
)
@@ -43,6 +44,10 @@ func nodeCall(ctx *Context, node *tree.Call) (vitess.Statement, error) {
4344
if len(node.Procedure.OrderBy) > 0 {
4445
return nil, errors.Errorf("procedure ORDER BY is not yet supported")
4546
}
47+
48+
ctx.Auth().PushAuthType(auth.AuthType_EXECUTE)
49+
defer ctx.Auth().PopAuthType()
50+
4651
var qualifier vitess.TableIdent
4752
var name vitess.ColIdent
4853
switch funcRef := node.Procedure.Func.FunctionReference.(type) {
@@ -66,5 +71,12 @@ func nodeCall(ctx *Context, node *tree.Call) (vitess.Statement, error) {
6671
return vitess.InjectedStatement{
6772
Statement: pgnodes.NewCall(qualifier.String(), name.String(), exprs),
6873
Children: exprs,
74+
Auth: vitess.AuthInformation{
75+
AuthType: auth.AuthType_EXECUTE,
76+
TargetType: auth.AuthTargetType_FunctionIdentifiers,
77+
TargetNames: []string{qualifier.String(), name.String()},
78+
// TODO: need to get argument types separated by comma ( check routineArgTypesKey function )
79+
Extra: "",
80+
},
6981
}, nil
7082
}

server/ast/create_function.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/dolthub/doltgresql/core/id"
2626
"github.com/dolthub/doltgresql/postgres/parser/parser"
2727
"github.com/dolthub/doltgresql/postgres/parser/sem/tree"
28+
"github.com/dolthub/doltgresql/server/auth"
2829
"github.com/dolthub/doltgresql/server/functions/framework"
2930
pgnodes "github.com/dolthub/doltgresql/server/node"
3031
"github.com/dolthub/doltgresql/server/plpgsql"
@@ -138,6 +139,11 @@ func nodeCreateFunction(ctx *Context, node *tree.CreateFunction) (vitess.Stateme
138139
sqlDefParsed,
139140
node.ReturnsSetOf,
140141
),
142+
Auth: vitess.AuthInformation{
143+
AuthType: auth.AuthType_CREATE,
144+
TargetType: auth.AuthTargetType_SchemaIdentifiers,
145+
TargetNames: []string{tableName.Catalog(), tableName.Schema()},
146+
},
141147
}, nil
142148
}
143149

server/ast/create_procedure.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/dolthub/doltgresql/core/procedures"
2424
"github.com/dolthub/doltgresql/postgres/parser/sem/tree"
2525
"github.com/dolthub/doltgresql/postgres/parser/types"
26+
"github.com/dolthub/doltgresql/server/auth"
2627
pgnodes "github.com/dolthub/doltgresql/server/node"
2728
"github.com/dolthub/doltgresql/server/plpgsql"
2829
pgtypes "github.com/dolthub/doltgresql/server/types"
@@ -112,5 +113,10 @@ func nodeCreateProcedure(ctx *Context, node *tree.CreateProcedure) (vitess.State
112113
sqlDef,
113114
sqlDefParsed,
114115
),
116+
Auth: vitess.AuthInformation{
117+
AuthType: auth.AuthType_CREATE,
118+
TargetType: auth.AuthTargetType_SchemaIdentifiers,
119+
TargetNames: []string{tableName.Catalog(), tableName.Schema()},
120+
},
115121
}, nil
116122
}

server/ast/create_sequence.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/dolthub/doltgresql/core/id"
2424
"github.com/dolthub/doltgresql/core/sequences"
2525
"github.com/dolthub/doltgresql/postgres/parser/sem/tree"
26+
"github.com/dolthub/doltgresql/server/auth"
2627
pgnodes "github.com/dolthub/doltgresql/server/node"
2728
pgtypes "github.com/dolthub/doltgresql/server/types"
2829
)
@@ -200,5 +201,10 @@ func nodeCreateSequence(ctx *Context, node *tree.CreateSequence) (vitess.Stateme
200201
OwnerColumn: ownerColumnName,
201202
}),
202203
Children: nil,
204+
Auth: vitess.AuthInformation{
205+
AuthType: auth.AuthType_CREATE,
206+
TargetType: auth.AuthTargetType_SchemaIdentifiers,
207+
TargetNames: []string{name.DbQualifier.String(), name.SchemaQualifier.String()},
208+
},
203209
}, nil
204210
}

0 commit comments

Comments
 (0)