Skip to content

sql: allow database prefixes for schema names#55647

Merged
craig[bot] merged 4 commits intocockroachdb:masterfrom
jayshrivastava:support-catalog-qualified-schema-names
Oct 27, 2020
Merged

sql: allow database prefixes for schema names#55647
craig[bot] merged 4 commits intocockroachdb:masterfrom
jayshrivastava:support-catalog-qualified-schema-names

Conversation

@jayshrivastava
Copy link
Copy Markdown
Contributor

@jayshrivastava jayshrivastava commented Oct 16, 2020

This PR adds optional database prefixes to schemas for the following ops:

  • CREATE SCHEMA ...
  • DROP SCHEMA ...
  • ALTER SCHEMA (only the source schema can be prefixed to prevent changing the database of a schema using ALTER SCHEMA thisdb.foo RENAME TO otherdb.bar)
  • GRANT ... ON SCHEMA ...
  • REVOKE ... ON SCHEMA ...
  • SHOW GRANTS ON SCHEMA ...

Schema names in statements such as ALTER TYPE t SET SCHEMA or ALTER TABLE t SET SCHEMA etc currently do not take database prefixes (this remains unchanged in this PR) to discourage the creation of cross database relations. Discussion notes for this are here.

Resolves #54295

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@jayshrivastava jayshrivastava force-pushed the support-catalog-qualified-schema-names branch from 9830144 to ebf5364 Compare October 17, 2020 16:42
@jayshrivastava jayshrivastava changed the title update sql.y to use new schema struct allow database prefixes for schema names Oct 17, 2020
@jayshrivastava jayshrivastava changed the title allow database prefixes for schema names sql: allow database prefixes for schema names Oct 17, 2020
@jayshrivastava jayshrivastava force-pushed the support-catalog-qualified-schema-names branch 8 times, most recently from dbfcc28 to f306633 Compare October 21, 2020 15:22
@jayshrivastava jayshrivastava marked this pull request as ready for review October 21, 2020 15:22
Copy link
Copy Markdown
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm_strong: just the nit

This is really great work!

Reviewed 7 of 7 files at r1, 9 of 9 files at r2, 6 of 6 files at r3, 9 of 9 files at r4.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @jayshrivastava)


pkg/sql/drop_schema.go, line 100 at r2 (raw file):

	}

	if err := d.resolveCollectedObjects(ctx, p, nil); err != nil {

why is this now nil? maybe add some commentary.

Also, our style guide is that you should comment the parameter when passing nil with /* db */

@jayshrivastava jayshrivastava force-pushed the support-catalog-qualified-schema-names branch from f306633 to 0052db3 Compare October 27, 2020 16:03
The CREATE SCHEMA statement was expanded to allow schema
names prefixed with database names. For example, the statement
`CREATE SCHEMA other_db.schema_name` is valid.

Release note (sql change): The CREATE SCHEMA statement was expanded
to allow schema names prefixed with database names.
The DROP SCHEMA statement was expanded to allow schema
names prefixed with database names. For example, the statement
`DROP SCHEMA schema_name, other_db.schema_name CASCADE` is valid.

Release note (sql change): The DROP SCHEMA statement was
expanded to allow schema names prefixed with database names.
The ALTER SCHEMA statement was expanded to allow the source
schema to be prefixed with a database name. For example,
`ALTER SCHEMA other_db.schema_name RENAME TO schema_name_1` is valid.

Release note (sql change): The ALTER SCHEMA statement was expanded
to allow the source schema to be prefixed with a database name.
The statements GRANT ... ON SCHEMA ...,
REVOKE ... ON SCHEMA ..., and SHOW GRANTS ON SCHEMA ... were all
updated to allow schema names prefixed with database names.

Release note (sql change): The statements GRANT ... ON SCHEMA ...,
REVOKE ... ON SCHEMA ..., and SHOW GRANTS ON SCHEMA ... were all
updated to allow schema names prefixed with database names.
@jayshrivastava jayshrivastava force-pushed the support-catalog-qualified-schema-names branch from 0052db3 to 45e3a80 Compare October 27, 2020 17:19
@jayshrivastava
Copy link
Copy Markdown
Contributor Author

bors r=ajwerner

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Oct 27, 2020

Build succeeded:

@craig craig bot merged commit e0cfa21 into cockroachdb:master Oct 27, 2020
@jayshrivastava jayshrivastava deleted the support-catalog-qualified-schema-names branch October 31, 2020 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sql: cannot do schema operations on a database different from the session's database

3 participants