#!/bin/bash
# Licensed Materials - Property of IBM
# 5724-I68
#
# (C) Copyright IBM Corp. 2000, 2006
#
# US Government Users Restricted Rights - Use, duplication, or
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

# Set the Dublin database to be migrated to Fresno

${ECHO}
${ECHO} "********************************************************"
${ECHO} "********************************************************"
${ECHO} "**"
${ECHO} MIGRATION_INFO_MIGRATE_SCHEMA_SH
${ECHO} MIGRATION_INFO_BACKUP_DB_WARNING_SH
${ECHO} "**"
${ECHO} "********************************************************"
${ECHO} "********************************************************"
${ECHO}

. ${TOP}/src/db/schema/util/set_db_localized.sh "$@"
_ERROR_LOGS=$TOP/logs/errfile.log

getErrorCountInLogFile()
{
    if [ ! -f $_ERROR_LOGS ]; then
        errorCount=0
    else
        errorCount=`cat $_ERROR_LOGS | wc -c`
    fi
}

DoStartAndPrepare()
{
    ${ECHO} 
    ${ECHO} $1
    ${ECHO} 

    getErrorCountInLogFile
    initial=$errorCount
}

DoEndAndReportError()
{

    getErrorCountInLogFile
    final=$errorCount

    if [ ! $initial -eq $final ]; then
        ${ECHO} $1 

        ${ECHO} "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        ${ECHO} $2
        ${ECHO} "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        ${ECHO} "MIGRATION_INFO_CHECK_ERROR_LOG_FILE $_ERROR_LOGS"
        exit -1

    fi
        ${ECHO} "-----------------------------------------"
        ${ECHO} $2
        ${ECHO} "-----------------------------------------"
       
}


DoStartAndPrepare "MIGRATION_INFO_UPDATING_SH tutl_lck_lock"
. ${DB_DIR}/util/run_db_cmd.sh --file=$DB_SCRIPTS/tutl_lck_lock.sql --errorfilter=yes 2>> $_ERROR_LOGS  | ${GREP} -Ev "ORA-01418:|ERROR|complete.|dropped.|created.|altered.|^$"

DoEndAndReportError  "MIGRATION_INFO_FAILED_SH tutl_lck_lock. " " MIGRATION_INFO_SUCCEEDED_SH tutl_lck_lock."

${ECHO} "-----------------------------------------"
${ECHO} MIGRATION_INFO_LAUNCH_FRESNO_MIGRATION_SH
${ECHO} "-----------------------------------------"
. ${TOP}/bin/migration/migrate5301to532.sh 12 2>> $_ERROR_LOGS
