#!/usr/bin/env bash

# Lae keskkonnamuutujad
source env.sh

# Kontrolli, kas skeem eksisteerib
schema_exists=$(psql ${CONNECTION_NAME} -tAc "SELECT 1 FROM information_schema.schemata WHERE schema_name='${destination_schema}';")

if [[ "$schema_exists" == "1" ]]; then
    echo "Skeem '${destination_schema}' on juba olemas."
else
    echo "Skeemi '${destination_schema}' ei leitud. Loon skeemi..."
    psql ${CONNECTION_NAME} -c "CREATE SCHEMA ${destination_schema};"
    echo "Skeem '${destination_schema}' on loodud."
fi
