/*****************************************************************************
*
* Filename         - $Workfile:   messages.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: messages table and associated items
*
* Language         - Oracle SQL*Plus script
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 2006
*
*****************************************************************************/


PROMPT Creating table MESSAGES

CREATE TABLE messages (
   message_id                    NUMBER(10)  NOT NULL,
   message_type                  VARCHAR2(3) NOT NULL,
   message_direction             CHAR(1)     NOT NULL,
   parts                         NUMBER(3),
   parts_received                NUMBER(3),
   version                       CHAR(5),
   flight_number                 CHAR(8),
   flight_date                   CHAR(5),
   carrier                       VARCHAR2(3),
   originating_airport           CHAR(3),
   flight_id                     NUMBER(10),
   processed_state               CHAR(1),
   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 messages add ( constraint messages_pk primary key (appn_row_id) using index tablespace &1._indexes);

ALTER TABLE messages ADD ( CONSTRAINT messages_uk1 unique (message_id) USING INDEX TABLESPACE &1._indexes);

ALTER TABLE messages ADD (   CONSTRAINT messages_message_direction_ch CHECK (message_direction IN ('I','O')));

ALTER TABLE messages ADD (   CONSTRAINT messages_processed_state_ch CHECK (processed_state IN ('U','P','E','R')));

COMMENT ON TABLE MESSAGES IS 'This table contains DCS messages, specifically BNS and BMM messages';

COMMENT ON COLUMN MESSAGES.CARRIER IS  'Carrier code';
COMMENT ON COLUMN MESSAGES.FLIGHT_DATE IS  'Flight date';
COMMENT ON COLUMN MESSAGES.FLIGHT_ID IS  'Flight identifier';
COMMENT ON COLUMN MESSAGES.FLIGHT_NUMBER IS  'Flight number';
COMMENT ON COLUMN MESSAGES.MESSAGE_DIRECTION IS  'Message direction (inbound or outbound)';
COMMENT ON COLUMN MESSAGES.MESSAGE_ID IS  'Message identifier';
COMMENT ON COLUMN MESSAGES.MESSAGE_TYPE IS  'The message type, either BNS or BMM';
COMMENT ON COLUMN MESSAGES.ORIGINATING_AIRPORT IS  'Originating airport for the message';
COMMENT ON COLUMN MESSAGES.PARTS IS  'The number of individual message parts.  Directly relates to the number of entries in the MESSAGE_PARTS table';
COMMENT ON COLUMN MESSAGES.PARTS_RECEIVED IS  'For incoming messages the number of message parts actually received';
COMMENT ON COLUMN MESSAGES.PROCESSED_STATE IS  'Indicates whether the message has been processed';
COMMENT ON COLUMN MESSAGES.VERSION IS  'The IATA version of the message.  The is taken from the .V line in the message';
COMMENT ON COLUMN MESSAGES.APPN_ROW_ID IS 'Unique sequence number for this row';
COMMENT ON COLUMN MESSAGES.ROW_CREATE_TIME IS 'The time the row was created';
COMMENT ON COLUMN MESSAGES.ROW_DATE_TIME IS 'The time the row was last modified';
COMMENT ON COLUMN MESSAGES.CUSER IS 'The user who created the row';
COMMENT ON COLUMN MESSAGES.MUSER IS 'The user who last modified the row';
COMMENT ON COLUMN MESSAGES.MTERM IS 'The terminal from which the last modifcation to this row was made';
COMMENT ON COLUMN MESSAGES.SYSTEM_ID IS 'The system identifier';
COMMENT ON COLUMN MESSAGES.SOURCE IS 'The process that last amended this row ';
COMMENT ON COLUMN MESSAGES.TO_BE_ARCHIVED IS 'Indicates that this row is to be archived or has been archived';

