#!/bin/bash
set -e

# Create separate database for Paperless-NGX if it doesn't exist
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
    SELECT 'CREATE DATABASE paperless_dev'
    WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'paperless_dev')\gexec

    SELECT 'CREATE DATABASE paperless'
    WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'paperless')\gexec
EOSQL
