#!/bin/bash
set -e

IFS=','
for databases in $WILDFLY_DATABASES
  do
  IFS=':' read name user password <<< $databases
  psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
    CREATE USER $user WITH PASSWORD '$password';
    CREATE DATABASE $name WITH OWNER $user;
EOSQL
done
