#!/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
}


executeWithTempFile "./../R2007-02-06/alterTeacherPersonalExpectations.sql" ./../R2007-02-06/alterTeacherPersonalExpectations.sql
executeWithTempFile "./../R2007-02-12/alterTableRegistration.sql" ./../R2007-02-12/alterTableRegistration.sql
executeWithTempFile "./../R2007-02-12/dropResearchEventParticipationTable.sql" ./../R2007-02-12/dropResearchEventParticipationTable.sql
executeWithTempFile "./../R2007-02-12/createResearchActivityTable.sql" ./../R2007-02-12/createResearchActivityTable.sql
executeWithTempFile "./../R2007-02-12/dropResearchEventTable.sql" ./../R2007-02-12/dropResearchEventTable.sql
executeWithTempFile "./../R2007-02-14/createTableExternalRegistrationData.sql" ./../R2007-02-14/createTableExternalRegistrationData.sql
executeWithTempFile "./../R2007-02-14/createPunctualRoomsOccupationRequestTables.sql" ./../R2007-02-14/createPunctualRoomsOccupationRequestTables.sql
executeWithTempFile "./../R2007-02-14/CreateDepartmentSiteFunctionalities.sql" ./../R2007-02-14/CreateDepartmentSiteFunctionalities.sql
executeWithTempFile "./../R2007-02-14/CreateDepartmentSite.sql" ./../R2007-02-14/CreateDepartmentSite.sql
executeWithTempFile "./../R2007-02-16/addDegreeCurricularPlanLQ.sql" ./../R2007-02-16/addDegreeCurricularPlanLQ.sql
executeWithTempFile "./../R2007-02-17/alterTableJustificationMotive.sql" ./../R2007-02-17/alterTableJustificationMotive.sql
executeWithTempFile "./../R2007-02-17/alterTableWorkScheduleType.sql" ./../R2007-02-17/alterTableWorkScheduleType.sql
executeWithTempFile "./../R2007-02-17/alterTableRoomOccupation.sql" ./../R2007-02-17/alterTableRoomOccupation.sql
executeWithTempFile "./../R2007-02-21/alterTablePartyType.sql" ./../R2007-02-21/alterTablePartyType.sql
executeWithTempFile "./../R2007-02-22/addDegreeCurricularPlanLERCI.sql" ./../R2007-02-22/addDegreeCurricularPlanLERCI.sql
executeWithTempFile "./../R2007-02-26/personPartName.sql" ./../R2007-02-26/personPartName.sql
executeWithTempFile "./../R2007-02-26/updateJustificationMotive.sql" ./../R2007-02-26/updateJustificationMotive.sql
executeWithTempFile "./../R2007-02-27/alterTableTeacherPersonalExpectation.sql" ./../R2007-02-27/alterTableTeacherPersonalExpectation.sql
executeWithTempFile "./../R2007-02-27/alterTableJustifications.sql" ./../R2007-02-27/alterTableJustifications.sql
executeWithTempFile "./../R2007-02-27/unitPartName.sql" ./../R2007-02-27/unitPartName.sql
