/*****************************************************************************
*
* Filename              - tracking_log.sql
*
* Project Name          - UltraTrak Database
*
* Source Code Identifier - UAS/URBRS/SS/10127
*
* Description           - Table creation script for TRACKING_LOG. 
*                         Stores the logs of the events and statuses generated 
*                         by the baggage handlers on the scanners
*
* Language              - Oracle PL/SQL
*
* File History          - For the development history run the Show History report in PVCS
*
* Copyright Ultra Electronics Airport Systems, 2003
*
*****************************************************************************/

PROMPT Creating table TRACKING_LOG

create table tracking_log (
   group_no                      varchar2(10),
   bag_tag                       char(10) not null,
   bag_tag1                      char(1) NULL,
   bag_tag2a                     char(3) NULL,
   bag_tag2b                     char(3) NOT NULL,
   bag_tag3                      number(10) NOT NULL,
   pax_id                        number(10) not null,
   flight_id                     number(10) not null,
   timestamp                     date not null,
   location                      char(6) not null,
   event_no                      number(10),
   status_no                     number(10),
   user_id                       number(10) not 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 tracking_log add ( constraint tracking_log_pk primary key (appn_row_id) using index tablespace &1._indexes);

alter table tracking_log add ( constraint tracking_log_uk1 unique (group_no,bag_tag,flight_id,timestamp,event_no,status_no,user_id) using index tablespace &1._indexes );

CREATE INDEX tracking_log_idx_flt ON tracking_log (flight_id, substr(bag_tag,2,9)) TABLESPACE &1._indexes;

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

COMMENT ON TABLE TRACKING_LOG IS 'This table contains bag tracking event logs';

COMMENT ON COLUMN TRACKING_LOG.BAG_TAG IS  'Ten digit bag tag number';
COMMENT ON COLUMN TRACKING_LOG.BAG_TAG1 IS  'First digit of the bag tag number';
COMMENT ON COLUMN TRACKING_LOG.BAG_TAG2A IS  'Bag tag carrier';
COMMENT ON COLUMN TRACKING_LOG.BAG_TAG2B IS  'Bag tag carrier number';
COMMENT ON COLUMN TRACKING_LOG.BAG_TAG3 IS  'Last six digits of the bag tag number';
COMMENT ON COLUMN TRACKING_LOG.EVENT_NO IS  'Tracking event number ';
COMMENT ON COLUMN TRACKING_LOG.FLIGHT_ID IS  'Flight identifier';
COMMENT ON COLUMN TRACKING_LOG.GROUP_NO IS  'Group number';
COMMENT ON COLUMN TRACKING_LOG.LOCATION IS  'Location code';
COMMENT ON COLUMN TRACKING_LOG.PAX_ID IS  'Passenger identifier';
COMMENT ON COLUMN TRACKING_LOG.STATUS_NO IS  'Status number';
COMMENT ON COLUMN TRACKING_LOG.TIMESTAMP IS  'Tracking log timestamp';
COMMENT ON COLUMN TRACKING_LOG.USER_ID IS  'User identifier';
COMMENT ON COLUMN TRACKING_LOG.APPN_ROW_ID IS 'Unique sequence number for this row';
COMMENT ON COLUMN TRACKING_LOG.ROW_CREATE_TIME IS 'The time the row was created';
COMMENT ON COLUMN TRACKING_LOG.ROW_DATE_TIME IS 'The time the row was last modified';
COMMENT ON COLUMN TRACKING_LOG.CUSER IS 'The user who created the row';
COMMENT ON COLUMN TRACKING_LOG.MUSER IS 'The user who last modified the row';
COMMENT ON COLUMN TRACKING_LOG.MTERM IS 'The terminal from which the last modifcation to this row was made';
COMMENT ON COLUMN TRACKING_LOG.SYSTEM_ID IS 'The system identifier';
COMMENT ON COLUMN TRACKING_LOG.SOURCE IS 'The process that last amended this row ';
COMMENT ON COLUMN TRACKING_LOG.TO_BE_ARCHIVED IS 'Indicates that this row is to be archived or has been archived';
