-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql: Support CREATE DATABASE WITH OWNER #74867
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, looks mostly good to me after minor comments are addressed.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @Fenil-P and @RichardJCai)
pkg/sql/descriptor.go, line 147 at r1 (raw file):
// database-level zone configuration if there is a region config on the // descriptor. //p.setNewDatabaseOwner(ctx)
Remove this comment.
pkg/sql/descriptor.go, line 148 at r1 (raw file):
// descriptor. //p.setNewDatabaseOwner(ctx) if database.Owner.Name != "" {
Use Owner.IsUndefined()
pkg/sql/descriptor.go, line 154 at r1 (raw file):
} if err := p.checkCanAlterToNewOwner(ctx, desc, newOwner); err != nil {
Not 100% sure if we need this check if we're creating a new database here.
Can you double check with Postgres - you'll have to download PG and verify.
Namely, check if you can CREATE DATABASE ... WITH OWNER ...
where the current user is not a member of the owner role.
Also please add a test for this if it turns out we do need this check (verify that we need to be a member of the owner role)
pkg/sql/descriptor.go, line 161 at r1 (raw file):
return nil, true, err } if err := p.writeNonDropDatabaseChange(
Don't need this since the database descriptor gets written later in this function.
07937d9
to
85e30e3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @RichardJCai)
pkg/sql/descriptor.go, line 147 at r1 (raw file):
Previously, RichardJCai (Richard Cai) wrote…
Remove this comment.
Done.
pkg/sql/descriptor.go, line 148 at r1 (raw file):
Previously, RichardJCai (Richard Cai) wrote…
Use
Owner.IsUndefined()
Done.
pkg/sql/descriptor.go, line 154 at r1 (raw file):
Previously, RichardJCai (Richard Cai) wrote…
Not 100% sure if we need this check if we're creating a new database here.
Can you double check with Postgres - you'll have to download PG and verify.Namely, check if you can
CREATE DATABASE ... WITH OWNER ...
where the current user is not a member of the owner role.Also please add a test for this if it turns out we do need this check (verify that we need to be a member of the owner role)
Done.
pkg/sql/descriptor.go, line 161 at r1 (raw file):
Previously, RichardJCai (Richard Cai) wrote…
Don't need this since the database descriptor gets written later in this function.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! LGTM after addressing nit
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @Fenil-P and @RichardJCai)
pkg/sql/descriptor.go, line 140 at r2 (raw file):
} else { owner = p.SessionData().User()
nit: we can just remove this else block and initially set owner to p.SessionData.User()
and update it if the if cond is met
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @Fenil-P, @rafiss, and @RichardJCai)
pkg/sql/descriptor.go, line 140 at r2 (raw file):
Previously, RichardJCai (Richard Cai) wrote…
nit: we can just remove this else block and initially set owner to
p.SessionData.User()
and update it if the if cond is met
+1
actually when is database.Owner ever undefined?
pkg/sql/parser/sql.y, line 8923 at r2 (raw file):
OWNER opt_equal role_spec { $$ = $3
should this be $$.val = $3.roleSpec()
maybe it's the same thing?
pkg/sql/parser/sql.y, line 8928 at r2 (raw file):
{ $$.val = tree.RoleSpec{ RoleSpecType: tree.SessionUser,
why SessionUser and not CurrentUser?
Release note (sql change): Allow users to specify the owner when creating a database. Similar to postgresql: CREATE DATABASE name [ [ WITH ] [ OWNER [=] user_name ]
85e30e3
to
bf237fd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @rafiss and @RichardJCai)
pkg/sql/descriptor.go, line 140 at r2 (raw file):
actually when is database.Owner ever undefined?
They're undefined when defaultdb and postgres are being created
pkg/sql/parser/sql.y, line 8923 at r2 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
should this be
$$.val = $3.roleSpec()
maybe it's the same thing?
I kept the opt_owner_clause the same type as role_spec so its done later on in the create db statement.
pkg/sql/parser/sql.y, line 8928 at r2 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
why SessionUser and not CurrentUser?
Updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @Fenil-P, @rafiss, and @RichardJCai)
pkg/sql/descriptor.go, line 140 at r2 (raw file):
Previously, Fenil-P (Fenil Patel) wrote…
actually when is database.Owner ever undefined?
They're undefined when defaultdb and postgres are being created
that happens in createDefaultDbs
in startupmigrations with CREATE DATABASE IF NOT EXISTS "%s"
but based on how you added the new syntax, shouldn't an empty owner
clause already default to using the current user?
anyway, this doesn't need to block the PR, i was just curious. having the undefined fallback case seems good regardless
bors r+ |
Build failed (retrying...): |
bors retry |
Already running a review |
bors r+ |
Already running a review |
Build succeeded: |
fixes #67817
Release note (sql change): Allow users to specify the owner when creating a database.
Similar to postgresql: CREATE DATABASE name [ [ WITH ] [ OWNER [=] user_name ]