#!/bin/bash
set -e

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" --port "${PGPORT:-5432}" <<-EOSQL
    CREATE USER pantheon WITH password 'test';
    ALTER USER pantheon WITH SUPERUSER;
    GRANT USAGE ON SCHEMA public TO pantheon;
    CREATE DATABASE pantheon;
    GRANT ALL PRIVILEGES ON DATABASE pantheon TO pantheon;
EOSQL



if test -f "/docker-entrypoint-initdb.d/dumps/pantheon.sql"; then
    psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname pantheon --port "${PGPORT:-5432}" < /docker-entrypoint-initdb.d/dumps/pantheon.sql
else
    echo "can not find pantheon db dump to load"
fi
