#!/bin/ksh
#
#  Rework anchoring flags, rename endpoint.pickup_only_enabled
#  Tied to build -129, CC V39
#

# migrate
#  $1 - absolute path to build.xml in test suite
#  $2 - phase
#     'before' - before loading
#     'migrate' - migrate data
#     'after' - after dump
#  returns - 0 success; 1 failure

#
# migration is to propagate domain type into endpoint type
# We need to have the constraint disabled because we can't
#  guarantee uniqueness and we don't want the insert to fail.  
#  At the end, we renable it as a test to test the data for after 
#  it's been inserted.

# We also need to return 1 if the migration has failed so the log
#  gets scanned.

case $2 in
	'before'| 'after' )
		exit 0
		;;

	'migrate')
		dbLog=db_$$.log
		rm -f $dbLog
		echo "Testcase = $1" >$dbLog
		cat <<EOF | sqlplus $CSN_DBUSER/$CSN_DBUSER@$CSN_DBSERVICE >>$dbLog 2>&1
  update mcs_identity_pref set forward_unconditional_type = 'VOICE_MAIL'
    where call_forwarding_enabled = 'Y' and forward_unconditional_enabled = 'Y';
  update mcs_identity_pref set forward_unconditional_type = 'OFF'
    where call_forwarding_enabled = 'Y' and forward_unconditional_enabled = 'N';

  update mcs_identity_pref set unconditional_vm_uri = unconditional_uri;

  exit;

EOF

		if [[ -z `grep ORA $dbLog` ]]
		then
			rm $dbLog
			exit 0
		else
			echo "log in `pwd`/$dbLog"
			exit 1
		fi
		;;

esac
