/*****************************************************************************
*
* Filename         - $Workfile:   flight_events.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 flight_events table.
*
* Language         - Oracle SQL*Plus script
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 1998
*
*****************************************************************************/
/****************************************************************************
* @(#)$Workfile:   flight_events.sql  $  $Revision:   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:   /pvcsarch/db_ora/db/source/live/tables/flight_events.svl  $
* 
*    Rev 1.1   21 Jun 2001 14:47:34   tagtrak
* OR:
* CR:
* Re-baseline version 4.0.0 to include patches.
* 
*    Rev 1.0   28 Sep 1998 13:22:14   tagtrak
* OR: 12265
* CR: 12265
* REV:
* Vienna enhancement - Log incoming flight data
* Andrew Walker
*
****************************************************************************/

PROMPT Creating table FLIGHT_EVENTS

create table flight_events (
   flight_no                     char(8)          not null,
   event_description             varchar2(40)     not null,
   log_time                      date             not null,
   user_id                       number(10)       not null,
   location_code                 char(6)          not null,
   flight_date                   char(5)          not null,
   flight_id                     number(10),
   flight_direction              char(1)          not null,
   event_key                     char(1),
   event_duration                char(1),
   end_log_time                  date,
   end_user_id                   number(10),
   end_location_code             char(6),
   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 flight_events add ( constraint flight_events_pk primary key (appn_row_id) using index tablespace &1._indexes);

alter table flight_events add ( constraint flight_events_direction check ( flight_direction in ('I', 'O') ));

alter table flight_events add ( constraint flight_events_fk_location foreign key ( location_code ) references location (location_code));

alter table flight_events add ( constraint flight_events_fk_end_location foreign key ( end_location_code ) references location (location_code));

alter table flight_events add ( constraint flight_events_fk_flight_id foreign key ( flight_id ) references flight (flight_id) on delete cascade);

create index flight_events_sk1 on flight_events(flight_no) tablespace &1._indexes; 

create index flight_events_sk2 on flight_events(flight_no,log_time) tablespace &1._indexes;

CREATE INDEX flight_events_sk3 ON flight_events(end_location_code) TABLESPACE &1._indexes;

CREATE INDEX flight_events_sk4 ON flight_events(flight_id) TABLESPACE &1._indexes;

CREATE INDEX flight_events_sk5 ON flight_events(location_code) TABLESPACE &1._indexes;

COMMENT ON TABLE FLIGHT_EVENTS IS 'This table contains flight events details. These entries are created by agents assigning flight event logs';

COMMENT ON COLUMN FLIGHT_EVENTS.END_LOCATION_CODE IS  'Location code';
COMMENT ON COLUMN FLIGHT_EVENTS.END_LOG_TIME IS  'Event end log time';
COMMENT ON COLUMN FLIGHT_EVENTS.END_USER_ID IS  'User identifier';
COMMENT ON COLUMN FLIGHT_EVENTS.EVENT_DESCRIPTION IS  'Event description';
COMMENT ON COLUMN FLIGHT_EVENTS.EVENT_DURATION IS  'Event duration';
COMMENT ON COLUMN FLIGHT_EVENTS.EVENT_KEY IS  'Event key';
COMMENT ON COLUMN FLIGHT_EVENTS.FLIGHT_DATE IS  'Flight date';
COMMENT ON COLUMN FLIGHT_EVENTS.FLIGHT_DIRECTION IS  'Flight direction (inbound or outbound)';
COMMENT ON COLUMN FLIGHT_EVENTS.FLIGHT_ID IS  'Flight identifier';
COMMENT ON COLUMN FLIGHT_EVENTS.FLIGHT_NO IS  'Flight number';
COMMENT ON COLUMN FLIGHT_EVENTS.LOCATION_CODE IS  'Location code';
COMMENT ON COLUMN FLIGHT_EVENTS.LOG_TIME IS  'Event log time';
COMMENT ON COLUMN FLIGHT_EVENTS.USER_ID IS  'User identifier';
COMMENT ON COLUMN FLIGHT_EVENTS.APPN_ROW_ID IS 'Unique sequence number for this row';
COMMENT ON COLUMN FLIGHT_EVENTS.ROW_CREATE_TIME IS 'The time the row was created';
COMMENT ON COLUMN FLIGHT_EVENTS.ROW_DATE_TIME IS 'The time the row was last modified';
COMMENT ON COLUMN FLIGHT_EVENTS.CUSER IS 'The user who created the row';
COMMENT ON COLUMN FLIGHT_EVENTS.MUSER IS 'The user who last modified the row';
COMMENT ON COLUMN FLIGHT_EVENTS.MTERM IS 'The terminal from which the last modifcation to this row was made';
COMMENT ON COLUMN FLIGHT_EVENTS.SYSTEM_ID IS 'The system identifier';
COMMENT ON COLUMN FLIGHT_EVENTS.SOURCE IS 'The process that last amended this row ';
COMMENT ON COLUMN FLIGHT_EVENTS.TO_BE_ARCHIVED IS 'Indicates that this row is to be archived or has been archived';
