#!/usr/bin/env bash

echo ""
echo "Starting integration test system for PipeDream Accounting."
echo ""
echo "**Please ensure you run this from a set up virtual env.**"
echo ""
echo "Once the server comes up, run 'python setup.py test' from the root"
echo ""

cd "$(dirname "$0")"

docker-compose up -d

export PIPEDREAM_ACCOUNTING__SLURM_STORE__INTEG_MODE="true"
export PGUSER="pipedream_accounting"
export PGPASSWORD="secret"
until psql -h "localhost" -c '\q'; do
  >&2 echo "Postgres is unavailable - sleeping"
  sleep 1
done

unset PGUSER
unset PGPASSWORD

echo ""
echo Connected to Postgres!;
echo ""

migrate upgrade head
run_server
