#!/bin/sh

set -e

case $USER in
        root) PGUSER=postgres ;;
        *)    PGUSER=$USER ;;
esac

PGPORT=65432

export PG_VIRTUALENV_ARGS=-oport=${PGPORT}

pg_buildext \
	virtualenv <<-EOF
		psql -c "CREATE DATABASE source_database"
		psql -c "CREATE DATABASE target_database"
		psql -c "ALTER USER ${PGUSER} PASSWORD 'autopkgtest'"
		sed -e s/@PGUSER@/${PGUSER}/ -e s/@PGPORT@/${PGPORT}/ debian/tests/config.yaml.in > debian/tests/config.yaml
		credativ-pg-migrator --config debian/tests/config.yaml
	EOF
