#!/bin/sh

set -ex

# make port 5432 available
service postgresql stop

export TZ=UTC

pg_buildext -o 'port=5432' virtualenv  <<-EOF
		set -ex
		psql -Xc 'CREATE EXTENSION pgtap'
		psql -Xc 'CREATE SCHEMA dblink'
		psql -Xc 'CREATE EXTENSION dblink WITH SCHEMA dblink'
		psql -Xc 'CREATE SCHEMA mimeo'
		psql -Xc 'CREATE EXTENSION mimeo WITH SCHEMA mimeo'
		# full run:
		#pg_prove -v -f test/*.sql
		# selected tests:
		pg_prove -v -f test/test01_setup.sql
		pg_prove -v -f test/test02_setup_remote_tables.sql
		pg_prove -v -f test/test03_run_maker_functions.sql
		#pg_prove -v -f test/test04_check_maker_data.sql
		#pg_prove -v -f test/test05_insert_remote_data_batch2.sql
		#pg_prove -v -f test/test06_run_refresh_functions.sql
		#pg_prove -v -f test/test07_check_refresh_data.sql
		#pg_prove -v -f test/test08_insert_remote_data_batch3.sql
		#pg_prove -v -f test/test09_check_refresh_data.sql
		#pg_prove -v -f test/test10_run_repull_tests.sql
		#pg_prove -v -f test/test11_test_individual_dml_types.sql
		#pg_prove -v -f test/test80_error_tests.sql
		#pg_prove -v -f test/test81_max_multi_dml_tables.sql
		#pg_prove -v -f test/test90_batch_limit_tests.sql
		#pg_prove -v -f test/test91_check_source_changes.sql
		pg_prove -v -f test/test98_run_destroyer_functions.sql
		pg_prove -v -f test/test99_cleanup.sql
EOF
