Skip to content

Commit

Permalink
Merge #60603
Browse files Browse the repository at this point in the history
60603: parser: add alias for ALTER DATABASE ... SET PRIMARY REGION r=ajstorm a=otan

Resolves #59247

Release note: None

Co-authored-by: Oliver Tan <[email protected]>
  • Loading branch information
craig[bot] and otan committed Feb 16, 2021
2 parents 0c62e88 + e7cc7a6 commit 497a9c0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/sql/alter_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (n *alterDatabaseAddRegionNode) startExec(params runParams) error {
n.n.Region.String(),
n.n.Name.String(),
),
"you must add a PRIMARY REGION first using ALTER DATABASE %s SET PRIMARY REGION %s",
"you must add a PRIMARY REGION first using ALTER DATABASE %s PRIMARY REGION %s",
n.n.Name.String(),
n.n.Region.String(),
)
Expand Down Expand Up @@ -308,7 +308,7 @@ func (p *planner) AlterDatabaseDropRegion(
return nil, errors.WithHintf(
errors.Newf("cannot drop region %q", dbDesc.RegionConfig.PrimaryRegion),
"You must designate another region as the primary region using "+
"ALTER DATABASE %s SET PRIMARY REGION <region name> or remove all other regions before "+
"ALTER DATABASE %s PRIMARY REGION <region name> or remove all other regions before "+
"attempting to drop region %q", dbDesc.GetName(), n.Region,
)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/logictest/testdata/logic_test/multiregion
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ ALTER DATABASE non_multi_region_db DROP REGION "ca-central-1"
statement ok
CREATE DATABASE drop_region_db PRIMARY REGION "ca-central-1" REGIONS "ap-southeast-2", "us-east-1"

statement error pq: cannot drop region "ca-central-1"\nHINT: You must designate another region as the primary region using ALTER DATABASE drop_region_db SET PRIMARY REGION <region name> or remove all other regions before attempting to drop region "ca-central-1"
statement error pq: cannot drop region "ca-central-1"\nHINT: You must designate another region as the primary region using ALTER DATABASE drop_region_db PRIMARY REGION <region name> or remove all other regions before attempting to drop region "ca-central-1"
ALTER DATABASE drop_region_db DROP REGION "ca-central-1"

statement ok
Expand Down Expand Up @@ -931,7 +931,7 @@ CREATE TABLE start_off_non_multi_region.public.t(a INT);
ALTER DATABASE start_off_non_multi_region PRIMARY REGION "ca-central-1";
ALTER DATABASE start_off_non_multi_region ADD REGION "ap-southeast-2"

statement error pq: cannot drop region "ca-central-1"\nHINT: You must designate another region as the primary region using ALTER DATABASE start_off_non_multi_region SET PRIMARY REGION <region name> or remove all other regions before attempting to drop region "ca-central-1"
statement error pq: cannot drop region "ca-central-1"\nHINT: You must designate another region as the primary region using ALTER DATABASE start_off_non_multi_region PRIMARY REGION <region name> or remove all other regions before attempting to drop region "ca-central-1"
ALTER DATABASE start_off_non_multi_region DROP REGION "ca-central-1"

statement ok
Expand Down Expand Up @@ -1026,7 +1026,7 @@ statement ok
ALTER DATABASE drop_primary_regions_db DROP REGION "ca-central-1"

# Cannot drop the primary region yet, as there are other regions in the db.
statement error pq: cannot drop region "us-east-1"\nHINT: You must designate another region as the primary region using ALTER DATABASE drop_primary_regions_db SET PRIMARY REGION <region name> or remove all other regions before attempting to drop region "us-east-1"
statement error pq: cannot drop region "us-east-1"\nHINT: You must designate another region as the primary region using ALTER DATABASE drop_primary_regions_db PRIMARY REGION <region name> or remove all other regions before attempting to drop region "us-east-1"
ALTER DATABASE drop_primary_regions_db DROP REGION "us-east-1"

statement ok
Expand Down
3 changes: 3 additions & 0 deletions pkg/sql/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,9 @@ func TestParse2(t *testing.T) {
`CREATE DATABASE a PRIMARY REGION = "us-west-1"`,
`CREATE DATABASE a PRIMARY REGION "us-west-1"`,
},
{`ALTER DATABASE a SET PRIMARY REGION "us-west-1"`,
`ALTER DATABASE a PRIMARY REGION "us-west-1"`},

{`CREATE TABLE a (b INT) WITH (fillfactor=100)`,
`CREATE TABLE a (b INT8)`},
{`CREATE TABLE a (b INT, UNIQUE INDEX foo (b))`,
Expand Down
10 changes: 9 additions & 1 deletion pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ alter_sequence_options_stmt:
// ALTER DATABASE <name> CONVERT TO SCHEMA WITH PARENT <name>
// ALTER DATABASE <name> ADD REGIONS <regions>
// ALTER DATABASE <name> DROP REGIONS <regions>
// ALTER DATABASE <name> SET PRIMARY REGION <region>
// ALTER DATABASE <name> PRIMARY REGION <region>
// ALTER DATABASE <name> SURVIVE <failure type>
// %SeeAlso: WEBDOCS/alter-database.html
alter_database_stmt:
Expand Down Expand Up @@ -1533,6 +1533,14 @@ alter_database_primary_region_stmt:
PrimaryRegion: tree.Name($4),
}
}
| ALTER DATABASE database_name SET primary_region_clause
{
/* SKIP DOC */
$$.val = &tree.AlterDatabasePrimaryRegion{
Name: tree.Name($3),
PrimaryRegion: tree.Name($5),
}
}

// %Help: ALTER RANGE - change the parameters of a range
// %Category: DDL
Expand Down

0 comments on commit 497a9c0

Please sign in to comment.