/*****************************************************************************
*
* Filename         - $Workfile:   bag_trace.sql  $
*
*                     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         - Live Schema: bag_trace table and associated items
*
* Language         - Oracle SQL*Plus script
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 1997
*
*****************************************************************************/
/****************************************************************************
* @(#)$Workfile:   bag_trace.sql  $  $Revision:   1.5  $
*
* 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:   /pvcsarch/db_ora/db/source/live/tables/bag_trace.svl  $
 * 
 *    Rev 1.5   21 Jun 2001 14:46:46   tagtrak
 * OR:
 * CR:
 * Re-baseline version 4.0.0 to include patches.
 * 
 *    Rev 1.4   10 Jun 1999 14:51:46   tagtrak
 * OR:
 * CR: 14043
 * REV:
 * Changed Archive and Backup so that the database
 * can be accessed during the eraseLive function.
 * 
 * Neil Bishop.
 * 
 *    Rev 1.3   26 Feb 1999 08:55:58   tagtrak
 *  
 * 
 *    Rev 1.2   02 Apr 1998 19:42:30   tagtrak
 * OR:
 * CR:
 * REV:
 * Initial Issue
 * See label for concession
 * 
 *    Rev 1.1   26 Feb 1998 11:07:26   tagtrak
 * OR:
 * CR:
 * REV:
 * Initial core product version
 * 
 *    Rev 1.0   22 Oct 1997 11:07:24   tagtrak
 * OR:
 * CR:
 * REV:
 * Initial check-in
*
****************************************************************************/

PROMPT Creating table BAG_TRACE

create table BAG_TRACE (
   PAX_ID                        NUMBER(10) NOT NULL,
   BAG_TRACE_TIME                DATE NOT NULL,
   ACTION_TIME                   DATE NOT NULL,
   USER_ID                       NUMBER(10) NOT NULL,
   LOCATION_CODE                 CHAR(6) NOT NULL,
   ERROR_ID                      NUMBER(10) NOT NULL,
   TRACE_ACTION                  CHAR(10) NOT NULL,
   SCANNER_ID                    CHAR(6) NOT NULL,
   BAG_TAG2B                     CHAR(3) NOT NULL,
   BAG_TAG3                      NUMBER(10) NOT NULL,
   FLIGHT_ID_SCAN                NUMBER(10) NULL,
   BAG_TAG1                      CHAR(1) NULL,
   BAG_TAG                       CHAR(10) NOT NULL,
   BAG_TAG2A                     CHAR(3) NULL,
   RECORD_ID                     NUMBER(10) NULL,
   ULD_NO                        CHAR(10),
   AIRPORT_CODE                  CHAR(3) NOT NULL,
   FLIGHT_DATE                   CHAR(5),
   FLIGHT_NO                     CHAR(8),
   LOCATION_DESCRIPTION          VARCHAR2(50),
   LOGINNAME                     CHAR(15),
   ERROR_DESCRIPTION             VARCHAR2(50),
   ALPHA_CODE                    CHAR(3),
   AOSS_FLIGHT_NO                CHAR(8),
   AOSS_FLIGHT_DATE              CHAR(5),
   STOP_REASON                   VARCHAR2(18) NULL,
   row_create_time               date,
   row_date_time                 date,
   cuser                         varchar2(30),
   muser                         varchar2(30),
   mterm                         varchar2(64),
   source                        varchar2(8),
   to_be_archived                varchar2(1),
   appn_row_id                   number(18) not null,
   system_id                     number(4) default 0 not null
);

alter table bag_trace add ( constraint bag_trace_pk primary key (appn_row_id) using index tablespace &1._indexes);

alter table bag_trace add ( constraint bag_trace_fk_tagtrak_users foreign key (user_id) references tagtrak_users ( user_id ));

alter table bag_trace add ( constraint bag_trace_fk_location foreign key (location_code) references location ( location_code ));

alter table bag_trace add ( constraint bag_trace_fk_error foreign key (error_id) references error ( error_id ));

create index BAG_TRACE_SK3 on BAG_TRACE(BAG_TAG3) tablespace &1._indexes;
 
create index BAG_TRACE_SK4 on BAG_TRACE(RECORD_ID) tablespace &1._indexes;

CREATE INDEX bag_trace_sk5 ON bag_trace(error_id) TABLESPACE &1._indexes;

CREATE INDEX bag_trace_sk6 ON bag_trace(location_code) TABLESPACE &1._indexes;

CREATE INDEX bag_trace_sk7 ON bag_trace(user_id) TABLESPACE &1._indexes;

CREATE INDEX bag_trace_idx_flt ON bag_trace (flight_id_scan, substr(bag_tag,2,9)) TABLESPACE &1._indexes;

CREATE INDEX bag_trace_idx_pax ON bag_trace (pax_id, substr(bag_tag,2,9)) TABLESPACE &1._indexes;

COMMENT ON TABLE BAG_TRACE IS 'This table contains trace information on the locations of bags';

COMMENT ON COLUMN BAG_TRACE.ACTION_TIME IS  'The time the bag trace entry was actioned';
COMMENT ON COLUMN BAG_TRACE.AIRPORT_CODE IS  'The airport code associated with this bag trace entry';
COMMENT ON COLUMN BAG_TRACE.ALPHA_CODE IS  'Alpha code';
COMMENT ON COLUMN BAG_TRACE.BAG_TAG IS  'The 10 digit bag tag number';
COMMENT ON COLUMN BAG_TRACE.BAG_TAG1 IS  'The first digit of the bag tag number';
COMMENT ON COLUMN BAG_TRACE.BAG_TAG2A IS  'The carrier associated with the bag tag';
COMMENT ON COLUMN BAG_TRACE.BAG_TAG2B IS  'The carrier number assoicated with the bag tag';
COMMENT ON COLUMN BAG_TRACE.BAG_TAG3 IS  'The last six digits of the bag tag';
COMMENT ON COLUMN BAG_TRACE.BAG_TRACE_TIME IS  'The time the bag trace row was created';
COMMENT ON COLUMN BAG_TRACE.ERROR_DESCRIPTION IS  'The error associated with this row if there is one';
COMMENT ON COLUMN BAG_TRACE.ERROR_ID IS  'The error identifer if appropriate';
COMMENT ON COLUMN BAG_TRACE.FLIGHT_DATE IS  'The flight date';
COMMENT ON COLUMN BAG_TRACE.FLIGHT_ID_SCAN IS  'The flight identifier';
COMMENT ON COLUMN BAG_TRACE.FLIGHT_NO IS  'The flight number';
COMMENT ON COLUMN BAG_TRACE.LOCATION_CODE IS  'The location of the bag';
COMMENT ON COLUMN BAG_TRACE.LOCATION_DESCRIPTION IS  'The location description';
COMMENT ON COLUMN BAG_TRACE.LOGINNAME IS  'The login name of the user associated with this entry';
COMMENT ON COLUMN BAG_TRACE.PAX_ID IS  'The passenger identifier';
COMMENT ON COLUMN BAG_TRACE.RECORD_ID IS  'The record identifier';
COMMENT ON COLUMN BAG_TRACE.SCANNER_ID IS  'The scanner identifier';
COMMENT ON COLUMN BAG_TRACE.TRACE_ACTION IS  'The trace action associated with this entry';
COMMENT ON COLUMN BAG_TRACE.ULD_NO IS  'The ULD number';
COMMENT ON COLUMN BAG_TRACE.USER_ID IS  'The user identifier';
COMMENT ON COLUMN BAG_TRACE.APPN_ROW_ID IS 'Unique sequence number for this row';
COMMENT ON COLUMN BAG_TRACE.ROW_CREATE_TIME IS 'The time the row was created';
COMMENT ON COLUMN BAG_TRACE.ROW_DATE_TIME IS 'The time the row was last modified';
COMMENT ON COLUMN BAG_TRACE.CUSER IS 'The user who created the row';
COMMENT ON COLUMN BAG_TRACE.MUSER IS 'The user who last modified the row';
COMMENT ON COLUMN BAG_TRACE.MTERM IS 'The terminal from which the last modifcation to this row was made';
COMMENT ON COLUMN BAG_TRACE.SYSTEM_ID IS 'The system identifier';
COMMENT ON COLUMN BAG_TRACE.SOURCE IS 'The process that last amended this row ';
COMMENT ON COLUMN BAG_TRACE.TO_BE_ARCHIVED IS 'Indicates that this row is to be archived or has been archived';
COMMENT ON COLUMN BAG_TRACE.AOSS_FLIGHT_NO IS 'Flight number as provided by AOSS/GSA';
COMMENT ON COLUMN BAG_TRACE.AOSS_FLIGHT_DATE IS 'Flight date as provided by AOSS/GSA';
COMMENT ON COLUMN BAG_TRACE.STOP_REASON IS 'The reason the bag is stopped';
