#!/usr/bin/env bash

choose_first_existing_file () {
    for f in "${@}"; do
        if [ -f "${f}" ]; then
            echo "${f}"
            break
        fi
    done
}

database=dosis2
owner=dsuper
psql_cmd="`choose_first_existing_file '/usr/pgsql-9.2/bin/psql' '/usr/lib/postgresql/10/bin/psql'`"


set -e

. /usr/share/dosis2/bin/shell-support-functions

${psql_cmd} -U ${owner} -d ${database} -f /opt/dosis2/database/db_views_delete_coldstorage.sql 
${psql_cmd} -U ${owner} -d ${database} -f /opt/dosis2/database/db_altertbl_jsonb_coldstorage.sql 
${psql_cmd} -U ${owner} -d ${database} -f /opt/dosis2/database/db_views_coldstorage.sql 



