# LogicTest: multiregion-15node-5region-3azs

statement ok
SET enable_super_regions = 'on'

# Basic cases, backup / restore database with super regions.

statement ok
CREATE DATABASE mr1 PRIMARY REGION "ca-central-1" REGIONS "us-east-1", "ap-southeast-2"

statement ok
ALTER DATABASE mr1 ADD SUPER REGION "test" VALUES "ap-southeast-2", "us-east-1"

statement ok
CREATE TABLE mr1.t(x INT) LOCALITY REGIONAL BY TABLE;
CREATE TABLE mr1.t2(x INT) LOCALITY REGIONAL BY ROW;

statement ok
BACKUP TABLE mr1.t INTO 'nodelocal://1/mr1_t/'

statement ok
BACKUP TABLE mr1.t2 INTO 'nodelocal://1/mr1_t2/'

statement ok
BACKUP DATABASE "mr1" INTO 'nodelocal://1/mr-backup-1/';

statement ok
DROP DATABASE mr1;

statement ok
RESTORE DATABASE "mr1" FROM LATEST IN 'nodelocal://1/mr-backup-1/'

query TT
SHOW ZONE CONFIGURATION FOR TABLE mr1.t;
----
DATABASE mr1  ALTER DATABASE mr1 CONFIGURE ZONE USING
                range_min_bytes = 134217728,
                range_max_bytes = 536870912,
                gc.ttlseconds = 14400,
                num_replicas = 5,
                num_voters = 3,
                constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
                voter_constraints = '[+region=ca-central-1]',
                lease_preferences = '[[+region=ca-central-1]]'

query TT
SHOW ZONE CONFIGURATION FOR TABLE mr1.t2
----
DATABASE mr1  ALTER DATABASE mr1 CONFIGURE ZONE USING
                range_min_bytes = 134217728,
                range_max_bytes = 536870912,
                gc.ttlseconds = 14400,
                num_replicas = 5,
                num_voters = 3,
                constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
                voter_constraints = '[+region=ca-central-1]',
                lease_preferences = '[[+region=ca-central-1]]'

query TT
SHOW ZONE CONFIGURATION FOR PARTITION "us-east-1" OF TABLE mr1.t2
----
PARTITION "us-east-1" OF TABLE mr1.public.t2  ALTER PARTITION "us-east-1" OF TABLE mr1.public.t2 CONFIGURE ZONE USING
                                                range_min_bytes = 134217728,
                                                range_max_bytes = 536870912,
                                                gc.ttlseconds = 14400,
                                                num_replicas = 4,
                                                num_voters = 3,
                                                constraints = '{+region=ap-southeast-2: 1, +region=us-east-1: 1}',
                                                voter_constraints = '[+region=us-east-1]',
                                                lease_preferences = '[[+region=us-east-1]]'

statement ok
DROP TABLE mr1.t;
DROP TABLE mr1.t2;

# Restore table into database with super regions.

statement ok
RESTORE TABLE mr1.t FROM LATEST IN 'nodelocal://1/mr1_t/'

statement ok
RESTORE TABLE mr1.t2 FROM LATEST IN 'nodelocal://1/mr1_t2/'

query TT
SHOW ZONE CONFIGURATION FOR TABLE mr1.t;
----
DATABASE mr1  ALTER DATABASE mr1 CONFIGURE ZONE USING
                range_min_bytes = 134217728,
                range_max_bytes = 536870912,
                gc.ttlseconds = 14400,
                num_replicas = 5,
                num_voters = 3,
                constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
                voter_constraints = '[+region=ca-central-1]',
                lease_preferences = '[[+region=ca-central-1]]'

query TT
SHOW ZONE CONFIGURATION FOR PARTITION "us-east-1" OF TABLE mr1.t2
----
PARTITION "us-east-1" OF TABLE mr1.public.t2  ALTER PARTITION "us-east-1" OF TABLE mr1.public.t2 CONFIGURE ZONE USING
                                                range_min_bytes = 134217728,
                                                range_max_bytes = 536870912,
                                                gc.ttlseconds = 14400,
                                                num_replicas = 4,
                                                num_voters = 3,
                                                constraints = '{+region=ap-southeast-2: 1, +region=us-east-1: 1}',
                                                voter_constraints = '[+region=us-east-1]',
                                                lease_preferences = '[[+region=us-east-1]]'

query TT
SHOW ZONE CONFIGURATION FOR TABLE mr1.t2
----
DATABASE mr1  ALTER DATABASE mr1 CONFIGURE ZONE USING
                range_min_bytes = 134217728,
                range_max_bytes = 536870912,
                gc.ttlseconds = 14400,
                num_replicas = 5,
                num_voters = 3,
                constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
                voter_constraints = '[+region=ca-central-1]',
                lease_preferences = '[[+region=ca-central-1]]'
