pubnode_dir=/tmp/pubnode
pubnode_port=54331
subnode_dir=/tmp/subnode
subnode_port=54332
initdb -D $pubnode_dir > /dev/null 2>&1
echo "wal_level=logical" >> $pubnode_dir/postgresql.conf
pg_ctl -D $pubnode_dir -o "-p $pubnode_port" start
psql -p $pubnode_port -c "create table objects (color text) partition by list (color)"
psql -p $pubnode_port -c "create table objects_green partition of objects for values in ('green')"
psql -p $pubnode_port -c "create table objects_yellow partition of objects for values in ('yellow')"
psql -p $pubnode_port -c "create publication pub for table objects, objects_green with (publish_via_partition_root = true)"
psql -p $pubnode_port -c "insert into objects values ('green'), ('yellow')"


initdb -D $subnode_dir > /dev/null 2>&1
pg_ctl -D $subnode_dir -o "-p $subnode_port" start
psql -p $subnode_port -c "create table objects (color text)"
psql -p $subnode_port -c "create table objects_green (color text)"
psql -p $subnode_port -c "create table objects_yellow (color text)"
psql -p $subnode_port -c "create subscription sub connection 'port=$pubnode_port' publication pub"
psql -p $subnode_port -c "table objects"
psql -p $subnode_port -c "table objects_green"

pg_ctl -D $pubnode_dir stop
rm -r $pubnode_dir
pg_ctl -D $subnode_dir stop
rm -r $subnode_dir
