#!/bin/bash

#
# Script to re-initialise the HPR2 database then rebuild it from the local
# MySQL copy (and ia.db for the IA parts). Also updates shows with multiple
# hosts by adding the missing hosts.
#

#
# Check that the ensuing destruction is really meant!
#
echo "** Warning** This script will DELETE the PostgreSQL database 'HPR2'"
read -r -p "Are you sure? [y/N] " ans
if [[ -z $ans || ${ans^^} = 'N' ]]; then
    echo "Aborting"
    exit
fi

#
# Directories
#
BASEDIR="$HOME/HPR/PostgreSQL_Database"
cd "$BASEDIR" || { echo "Failed to cd to $BASEDIR"; exit 1; }

#
# Drops all tables, etc and re-creates them
#
psql -U hpradmin HPR2 < hpr_schema_2.pgsql

#
# Does all phases in order by default
#
./copy_mysql_pg_2 -verb

#
# Adds in all the double hosts we know about at the moment
#
./update_multi-host_shows.sh