Skip to content
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: reduce UX surprise with DROP DATABASE and ALTER DATABASE RENAME #24246

Merged
merged 1 commit into from Mar 27, 2018

Conversation

knz
Copy link
Contributor

@knz knz commented Mar 27, 2018

Fixes #23661. cc @dianasaur323

Prior to this patch, a user logged into the CLI shell and taking a
database name's away while it is set as "current database", either via
DROP DATABASE or ALTER DATABASE RENAME, would cause the subsequent
prompt refresh and possibly further statements to fail, due to an
inexistent current database.

This behavior is arguably surprising and raises the question for
unsuspecting/beginner users: why does the thing let me do something
that breaks everything afterwards?

This patch enhances the issue by preventing DROP or ALTER DATABASE
RENAME if the name taken away is set as current database, when
sql_safe_updates is set. (It is set for interactive sessions with
cockroach sql).

The following alternatives were explored but eventually dismissed:

  • prevent DROP or ALTER DATABASE RENAME altogether on the current
    database. This is unfriendly to client apps which may expect "DROP
    DATABASE" followed immediately by "CREATE DATABASE" to keep the
    session valid.

  • allow DROP and ALTER DATABASE RENAME but silently change the current
    database to empty (or some other valid value, like "system"). This
    is unfriendly to client apps which only set the current database via
    a URL path and expect the setting to remain stable.

Release note (sql change): DROP DATABASE and ALTER DATABASE RENAME
now prevent the removal of a database name if that database is set as
the current database (SET database / USE) and the session setting
sql_safe_updates is also set.

Prior to this patch, a user logged into the CLI shell and taking a
database name's away while it is set as "current database", either via
DROP DATABASE or ALTER DATABASE RENAME, would cause the subsequent
prompt refresh and possibly further statements to fail, due to an
inexistent current database.

This behavior is arguably surprising and raises the question for
unsuspecting/beginner users: why does the thing let me do something
that breaks everything afterwards?

This patch enhances the issue by preventing DROP or ALTER DATABASE
RENAME if the name taken away is set as current database, when
`sql_safe_updates` is set. (It is set for interactive sessions with
`cockroach sql`).

The following alternatives were explored but eventually dismissed:

- prevent DROP or ALTER DATABASE RENAME altogether on the current
  database. This is unfriendly to client apps which may expect "DROP
  DATABASE" followed immediately by "CREATE DATABASE" to keep the
  session valid.

- allow DROP and ALTER DATABASE RENAME but silently change the current
  database to empty (or some other valid value, like "system"). This
  is unfriendly to client apps which only set the current database via
  a URL path and expect the setting to remain stable.

Release note (sql change): `DROP DATABASE` and `ALTER DATABASE RENAME`
now prevent the removal of a database name if that database is set as
the current database (`SET database` / `USE`) and the session setting
`sql_safe_updates` is also set.
@knz knz requested review from m-schneider and a team March 27, 2018 10:41
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@m-schneider
Copy link
Contributor

:lgtm:


Comments from Reviewable

@knz
Copy link
Contributor Author

knz commented Mar 27, 2018

Thanks!

@knz knz merged commit e22c658 into cockroachdb:master Mar 27, 2018
@knz
Copy link
Contributor Author

knz commented Mar 27, 2018

@dianasaur323 lmk if this needs to be cherry picked

@dianasaur323
Copy link
Contributor

dianasaur323 commented Mar 27, 2018 via email

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.

None yet

4 participants