#!/bin/ksh

# migrate
#  $1 - absolute patch 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.

if [[ $2 != migrate ]]
then
	exit 0
fi

dbLog=db_$$.log
rm -f $dbLog
echo "Testcase = $1" >$dbLog
cat <<EOF | sqlplus $CSN_DBUSER/$CSN_DBUSER@$CSN_DBSERVICE >>$dbLog 2>&1

   update endpoint
      set endpoint_type =
          (select domain_type 
				  from domain 
				  where domain_id = direct_association_domain_id
		  );

   alter table endpoint enable constraint endpoint_uk_address;
   alter table endpoint disable constraint endpoint_uk_address;

   exit;

EOF

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