-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release note (sql change): Support ALTER SCHEMA <schema> OWNER TO <owner> The command changes the owner of a schema. To use the conditions, the following conditions must be met: The user executing the command must be the of the schema. The user executing the command must be a member of the new owner role. The new owner role must have CREATE on the database the schema belongs to.
- Loading branch information
1 parent
7023c94
commit 4e82470
Showing
6 changed files
with
144 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
statement ok | ||
SET experimental_enable_user_defined_schemas = true | ||
|
||
statement ok | ||
CREATE SCHEMA s | ||
|
||
# Ensure user must exist for set owner. | ||
statement error pq: role/user "fake_user" does not exist | ||
ALTER SCHEMA s OWNER TO fake_user | ||
|
||
# Ensure the current user is a member of the role we're setting to. | ||
statement error pq: must be member of role "testuser" | ||
ALTER SCHEMA s OWNER TO testuser | ||
|
||
user testuser | ||
|
||
# Ensure the user has to be an owner to alter the owner. | ||
statement error pq: must be owner of schema s | ||
ALTER SCHEMA s OWNER TO testuser | ||
|
||
user root | ||
|
||
statement ok | ||
GRANT testuser TO root | ||
|
||
statement ok | ||
CREATE USER testuser2 | ||
|
||
statement ok | ||
GRANT testuser2 TO root | ||
|
||
# Ensure the desired owner has CREATE privilege on the database. | ||
statement error pq: user testuser2 does not have CREATE privilege on database test | ||
ALTER SCHEMA s OWNER TO testuser2 | ||
|
||
statement ok | ||
GRANT CREATE ON DATABASE test TO testuser, testuser2 | ||
|
||
# testuser has the required privileges to become the new owner of schema s. | ||
statement ok | ||
ALTER SCHEMA s OWNER TO testuser | ||
|
||
# setup to allow testuser2 as a member of testuser to alter the owner. | ||
statement ok | ||
REVOKE testuser, testuser2 FROM root | ||
|
||
statement ok | ||
GRANT testuser TO testuser2 | ||
|
||
statement ok | ||
GRANT root TO testuser | ||
|
||
user testuser2 | ||
|
||
# testuser2 should be able to alter the owner since it is a member of testuser. | ||
statement ok | ||
ALTER SCHEMA s OWNER TO root | ||
|
||
# set the owner back to testuser. | ||
|
||
user root | ||
|
||
statement ok | ||
REVOKE root FROM testuser | ||
|
||
statement ok | ||
GRANT testuser TO root | ||
|
||
statement ok | ||
ALTER SCHEMA s OWNER TO testuser | ||
|
||
# setup to allow testuser2 to become the owner again. | ||
statement ok | ||
REVOKE testuser FROM testuser2 | ||
|
||
statement ok | ||
GRANT testuser2 TO testuser | ||
|
||
# Ensure testuser is owner by dropping the schema. | ||
statement ok | ||
DROP SCHEMA s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters