#!/bin/csh -f

##############################################################################
#
# Filename         - $Workfile:   mk_temp_schema.csh  $
#
#                     Name              Date      Version     CR Number
# Author           - See revision history below.
# Last Update      - See revision history below.
#
# Project Name     - TAGTRAK(Oracle database)
#
# Source Code
# Identifier       - 0/3/300/8010/112
#
# Design Spec
# Section          -
#
# Contents         -
#     Build the Temp schema under the given username, which
#     must already exist as an Oracle user account.
#
# Language         - UNIX C-shell script
#
# Classification   - Commercial In Confidence
#
#          (c) Ultra Electronics Limited, 1997
#
##############################################################################

##############################################################################
# @(#)$Workfile:   mk_temp_schema.csh  $  $Revision:   1.10.1.1  $
#
# Revision History
#
# Note that user tagtrak is many users. For these users the user
# name is entered as the last line in the change description.
#
# $Log:   P:/PVCSDATA/UltraTrakCore/Database/arch_schema/mk_temp_schema.csh-arc  $
# 
#    Rev 1.10.1.1   Oct 25 2007 15:58:02   gary.roberts
# CA02851 - Fix 9.17 ATS7 build issues
# 
#    Rev 1.10.1.0   23 Aug 2007 17:33:12   dave.banks
# CA02607 - Dbinit changes for removal of arbk
# 
#    Rev 1.10   Jul 02 2007 12:24:18   phil.burns
# Move 9.16.2 to trunk
# 
#    Rev 1.9.1.4   24 May 2007 16:18:56   dave.banks
# CA02526 - Minor dbinit errors
# 
#    Rev 1.9.1.3   May 11 2007 11:10:36   robert.cooke
# CA02444
# 
#    Rev 1.9.1.2   May 11 2007 11:08:26   robert.cooke
# CA02444
# 
#    Rev 1.9.1.1   09 May 2007 10:55:22   Dave.banks
# CA02369 - Merged from 9.13.0.0.0.7
# 
#    Rev 1.9.1.0   22 Mar 2007 17:04:40   gary.roberts
# CA02341 - BVIS Subheader on BAG and FLIGHT tables should be RAW datatype
# 
#    Rev 1.9   08 Nov 2006 11:42:00   ian.byass
# Move Core 9.14.1 to Trunk
# 
#    Rev 1.8.2.0   Jun 01 2006 16:26:48   dave.banks
# UAS/FALCP/CA/01791 - Add option for Master Standby
# 
#    Rev 1.8   15 Nov 2005 10:31:02   david.rolfe
# Core 9.12 moved to tip
# 
#    Rev 1.7   06 Oct 2005 14:04:36   david.rolfe
# CA1534
# 
#    Rev 1.6   14 Jan 2005 19:57:40   peter.charalambous
# FALCP/CA/1149 - removed disable contraints for reflight tables since a fix to the constraints has now been made via FALCP/CA/1008.
#
#    Rev 1.5   19 Nov 2004 15:01:30   peter.charalambous
# FALCP/CA/1083 - Core 9 fixes to Expired Schema issues with not displaying bag trace details via MWS
#
#    Rev 1.5   19 Nov 2004 12:37:46   peter.charalambous
# FALCP/CA/1083 - Core 9 fixes to Expired Schema bag trace details not being dispalyed in bag trace screen.
#
#    Rev 1.4   18 Nov 2004 12:17:42   peter.charalambous
# FALCP/CA/1074 - Added statements to alter constraints which have been causing the archive and backup process to fail.
#
#    Rev 1.3   Sep 21 2004 14:17:04   mik.davis
# FACLP/CA/856
#
#    Rev 1.2   Sep 21 2004 12:04:44   mik.davis
# FALCP/CA/856
#
#    Rev 1.1   Oct 10 2003 10:25:32   peter.dawson
# FAS / FALCP / CA / 261
# Equipment Tracking for BARA Phase 2
#
#    Rev 1.0   Sep 22 2003 14:25:08   mik.davis
# Initial revision.
#
#    Rev 1.3   06 Jun 2000 09:12:32   tagtrak
#
#
#    Rev 1.2   12 Oct 1998 16:41:02   tagtrak
# OR: 12682 12683 12678 12654 12419 12265 12805 12285
# CR: 12682 12683 12678 12654 12419 12265 12805
# REV:
# Vienna enhancements/fixes for database V0.4.1E
# branch ATS revision moved to trunk.
# Andrew Walker
#
#    Rev 1.1.1.0   25 Sep 1998 12:36:00   tagtrak
# OR: 12682 12683 12678 12654 12419 12265 12285
# CR: 12682 12683 12678 12654 12419 12265
# REV:
# Vienna enhancements for Database 0.4.1
# Andrew Walker
#
#    Rev 1.1   02 Apr 1998 18:48:46   tagtrak
# OR:
# CR:
# REV:
# Initial Issue
#
#    Rev 1.0   26 Feb 1998 14:37:02   tagtrak
# OR:
# CR:
# REV:
# Initial Core product version
#
#    Rev 1.2   06 Nov 1997 13:47:06   tagtrak
# OR:
# CR:
# REV:
# Will use Instance identifier from caller's environment
#
#    Rev 1.1   28 Oct 1997 16:42:00   tagtrak
# date and time created 97/10/28 16:43:50 by andrew
#
##############################################################################


if ( $#argv != 2 ) then
	echo usage: $0 username passwd
	exit 1
endif

echo "Instance: " $ORACLE_SID
sleep 2

# Create temp tables

sqlplus $1/$2 << EOM
@tables/tables.sql temp;
exit;
EOM

# Create temp grants

grant_temp_to_arch

# Create synonyms

sqlplus $1/$2 << EOM
@tables/syns.sql
EOM

# Remove all foreign key constraints

remove_fk_cons $1/$2

sqlplus $1/$2 << EOM
create synonym eql_id_s for live.eql_id_s;
@stored_procs/arch_procs.sql;
@stored_procs/add_bag_data.sql;
@views/all_views.sql;
@stored_procs/no_archive_modify.sql
@triggers/all_triggs.sql;
GRANT INSERT ON TEMP.REFLIGHT_BAG TO ARCH;
GRANT INSERT ON TEMP.REFLIGHT_FLIGHT TO ARCH;
GRANT INSERT ON TEMP.REFLIGHT_PAX TO ARCH;
GRANT INSERT ON TEMP.REFLIGHT_ULDS TO ARCH;
GRANT SELECT ON TEMP.MACH_FLIGHT_INFO TO ARCH;
GRANT DELETE ON TEMP.MACH_FLIGHT_INFO TO ARCH;
exit;
EOM

# Finally grant access to/from ops$

echo "Creating grants to/from OPS schema ..."

../ops_schema/create_ops_grants $1/$2
../ops_schema/create_ops_synonyms $1/$2


