CREATE SCHEMA upgrade_basic;
SET search_path TO upgrade_basic, public;
CREATE TABLE t(a int);
CREATE INDEX ON t USING HASH (a);
SELECT create_distributed_table('t', 'a');
 create_distributed_table
---------------------------------------------------------------------

(1 row)

INSERT INTO t SELECT * FROM generate_series(1, 5);
CREATE TABLE tp(a int PRIMARY KEY);
SELECT create_distributed_table('tp', 'a');
 create_distributed_table
---------------------------------------------------------------------

(1 row)

INSERT INTO tp SELECT * FROM generate_series(1, 5);
-- We store the index of distribution column and here we check that the distribution
-- column index does not change after an upgrade if we drop a column that comes before the
-- distribution column. The index information is in partkey column of pg_dist_partition table.
CREATE TABLE t_ab(a int, b int);
SELECT create_distributed_table('t_ab', 'b');
 create_distributed_table
---------------------------------------------------------------------

(1 row)

INSERT INTO t_ab VALUES (1, 11);
INSERT INTO t_ab VALUES (2, 22);
INSERT INTO t_ab VALUES (3, 33);
CREATE TABLE t2(a int, b int);
INSERT INTO t2 VALUES (1, 11);
INSERT INTO t2 VALUES (2, 22);
INSERT INTO t2 VALUES (3, 33);
ALTER TABLE t_ab DROP a;
-- Check that basic reference tables work
CREATE TABLE r(a int PRIMARY KEY);
SELECT create_reference_table('r');
 create_reference_table
---------------------------------------------------------------------

(1 row)

INSERT INTO r SELECT * FROM generate_series(1, 5);
CREATE TABLE tr(pk int, a int REFERENCES r(a) ON DELETE CASCADE ON UPDATE CASCADE);
SELECT create_distributed_table('tr', 'pk');
 create_distributed_table
---------------------------------------------------------------------

(1 row)

INSERT INTO tr SELECT c, c FROM generate_series(1, 5) as c;
CREATE TABLE t_append(id int, value_1 int);
SELECT master_create_distributed_table('t_append', 'id', 'append');
 master_create_distributed_table
---------------------------------------------------------------------

(1 row)

\copy t_append FROM STDIN DELIMITER ','
\copy t_append FROM STDIN DELIMITER ','
