#!/bin/bash

if [ "$#" -ne 3 ]
then
    echo "*********************************************************************************************"
    echo "Incorrect usage."
    echo
    echo "Correct Syntax : ./loadDataForTest.sh <mysql_username> <mysql_password> <mysql_hostname>"
    echo
    echo "This script should only be used in the QA or Dev environments as it"
    echo "exposes the mysql login credentials through the command line."
    echo
    echo "This script should be run from the aml-data-tool/src/main/resources/db folder in the"
    echo "aml-data-tool repository."
    echo 
    echo "*********************************************************************************************"
    exit
fi

username=${1}
password=${2}
hostname=${3}

for schemaDir in biz_function_location content_repository mms_common smb tsacommon warehouse_1
do
  echo "Loading content for $schemaDir"
  cd $schemaDir/test-data
  for file in *.sql
  do
    echo "Loading file $file"
    queryCounter=0
    while read line; do
      mysql -u $username -p$password -h $hostname $schemaDir -e "$line" &
      let queryCounter++
      if (( queryCounter % 100 == 0 ))
      then
        sleep 1s
      fi
    done < $file
  done
  cd ../../
done
