#!/bin/sh

DEFDB=$1
DEFSRC=$2
DEFSERIAL=$3


# Specify where the database resides
MYSQL=/usr/package/mysql/bin/mysql
#MYSQL=/usr/local/mysql/bin/mysql
HOST=myhost.mydb.net
USER=user
PASSWORD=password
# the databse name
DB=${DEFDB:?"Database name is not set Usage empty_db db_name [source [serial]]"}
LOG=DBmake.$$.log
SOURCE=${DEFSRC:=RIPE}


# RIPE.CURRENTSERIAL
#CURRENTSERIAL=`cat ${OBJDIR}/RIPE.CURRENTSERIAL`
CURRENTSERIAL=${DEFSERIAL:=1}

echo
echo "Starting to make a database"
echo "    source: $SOURCE"
echo "***************************"
echo 
echo "Database: ${DB}@${HOST}"
echo "User: $USER"
echo "Password: $PASSWORD"
echo ""
echo "CURRENTSERIAL=" ${CURRENTSERIAL}
echo "Logging results in $LOG"
echo "***************************"
echo
echo "Accept and continue?"

read ANS dummy

if [ $ANS != 'Y' ] 
then
	exit;
fi

echo "OK"
export MYSQL HOST USER PASSWORD DB LOG CURRENTSERIAL SOURCE


echo "*******************"`date`"******************" >$LOG
echo "Creating tables\n" >>$LOG
echo "Creating tables\n"

cd SQL; ./create.first-stage >>../$LOG; cd ..

echo `date`"\n" >>$LOG
echo "Making indexes\n" >>$LOG
echo "Making indexes\n" 

cd SQL; ./create.second-stage >>../$LOG; cd ..

echo `date`"\n" >>$LOG
echo "Making more indexes\n" >>$LOG
echo "Making more indexes\n" 

cd SQL; ./create.third-stage >>../$LOG; cd ..

echo "Finished "`date` >>$LOG
echo "Finished "`date` 

