#!/bin/sh
# -----------------------------------------------------------------------------
#
#   Runs sql scripts to update database from previous release.
#
# -----------------------------------------------------------------------------
#

DB=$1
USER=$2

echo Using database: $DB
echo Enter password for $USER:
read -s password

function execute() {
	echo ---------------------------------------- $1
	mysql -u$USER -f -p$password --default-character-set=latin1 $DB < $2
	echo
}

function executeWithTempFile() {
	echo ---------------------------------------- $1
	mysql -u$USER -f -p$password --default-character-set=latin1 $DB < $2 > tmp.sql
	mysql -u$USER -f -p$password --default-character-set=latin1 $DB < tmp.sql	
	rm tmp.sql
	echo
}

execute "Alter Relation between Events and AcademicServices" alterRelationBetweenEventsAndAcademicServices.sql

execute "Drop column from AccountingTransaction" AlterTableAccountingTransaction.sql
execute "Add key CreditNote to accounting entry table" AlterTableAccountingEntry.sql
execute "Create CreditNote tables" CreateCreditNoteTables.sql
execute "Alter table AccountingEvent" AlterTableAccountingEvent.sql
execute "Alter Table Receipt" AlterTableReceipt.sql
execute "Changing AccountingEntry to Receipt Relation to M-N" ChangeAccountingEntryRelationWithReceipt.sql

