# LogicTest: multiregion-9node-3region-3azs multiregion-9node-3region-3azs-tenant multiregion-9node-3region-3azs-no-los

statement ok
SET CLUSTER SETTING sql.defaults.primary_region = "invalid-region-name";

statement ok
SET CLUSTER SETTING sql.multiregion.drop_primary_region.enabled = 'off'

# Test invalid default primary region name.

statement error region "invalid-region-name" does not exist
CREATE DATABASE db

statement ok
SET CLUSTER SETTING sql.defaults.primary_region = 'ap-southeast-2'

# If users have regions defined, still error if PRIMARY REGION is not set

statement error PRIMARY REGION must be specified if REGIONS are specified
CREATE DATABASE db REGIONS "us-east1"

query T noticetrace retry
CREATE DATABASE db
----
NOTICE: defaulting to 'WITH PRIMARY REGION "ap-southeast-2"' as no primary region was specified

query TTBBT colnames
SHOW REGIONS FROM DATABASE db
----
database  region          primary  secondary  zones
db        ap-southeast-2  true     false      {ap-az1,ap-az2,ap-az3}

statement ok
CREATE DATABASE db_explicit_primary_region PRIMARY REGION "us-east-1" REGIONS "ap-southeast-2"

query TTBBT colnames,rowsort
SHOW REGIONS FROM DATABASE db_explicit_primary_region
----
database                    region          primary  secondary  zones
db_explicit_primary_region  us-east-1       true     false      {us-az1,us-az2,us-az3}
db_explicit_primary_region  ap-southeast-2  false    false      {ap-az1,ap-az2,ap-az3}

# Test that we cannot drop the PRIMARY REGION.

statement error databases in this cluster must have at least 1 region
ALTER DATABASE db DROP REGION "ap-southeast-2"

statement error cannot drop region "us-east-1"
ALTER DATABASE db_explicit_primary_region DROP REGION "us-east-1"

statement ok
ALTER DATABASE db_explicit_primary_region DROP REGION "ap-southeast-2"

statement error databases in this cluster must have at least 1 region
ALTER DATABASE db_explicit_primary_region DROP REGION "us-east-1"
