#!/bin/bash
set -e

# Создаем пользователя redmine и БД redminedb
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
    CREATE USER redmine WITH PASSWORD 'redmine-password';
    CREATE DATABASE redminedb;
    GRANT ALL PRIVILEGES ON DATABASE redminedb TO redmine;
EOSQL

# Даем права на схему public
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USERNAME" -d redminedb <<-EOSQL
    ALTER SCHEMA public OWNER TO redmine;
    GRANT ALL ON SCHEMA public TO redmine;
EOSQL