#!/usr/bin/env bash
set -e

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
    CREATE USER $IMPORT_EXPORT_POSTGRESQL_USER WITH PASSWORD '$IMPORT_EXPORT_POSTGRESQL_PASSWORD';
    CREATE DATABASE $DB_NAME ENCODING 'utf-8';
    GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $IMPORT_EXPORT_POSTGRESQL_USER;
    ALTER USER $IMPORT_EXPORT_POSTGRESQL_USER CREATEDB;
EOSQL