#!/bin/bash

echo 'Clean up'

pg_ctl stop -D data_N2
pg_ctl stop -D data_N1

rm -rf data_* *log

echo 'Set up'

initdb -D data_N1 -U postgres -c "wal_level=logical"
pg_ctl -D data_N1 start -w -l N1.log

(
     echo -e "
CREATE TABLE t1 (a regclass);
create publication pub1 for table t1;
INSERT INTO t1 values('t1');
"
) | psql -U postgres


initdb -D data_N2 -U postgres -c "port=9000"
pg_ctl -D data_N2 start -w -l N2.log

(
     echo -e "
CREATE TABLE t1 (a text);
create subscription test1 connection 'user=postgres port=5432' publication pub1 with (binary = true);
"
) | psql -U postgres -p 9000
