#!/bin/bash
#
# reinit_db
#
# v0.1 2015-11-16 RE
#
# script that allows to re-run all database update scripts

MYSELF=$( basename $0 )

BAKDIR=backup
DEFDIR=db_initial

if [[ $UID -gt 0 ]]
then
    echo "$MYSELF needs to be run as superuser. You are $USER."
    exit 1
fi

echo "Re-running the installed database update scripts"
FILE_LIST=$( ls /${BAKDIR}/${DEFDIR}/3*patches*sql 2>/dev/null )
for file in ${FILE_LIST}; do
    echo ${file}
    su - postgres -c "psql -d recordum < "${file}
done

exit 0
