/*****************************************************************************
*
* Filename         - $Workfile:   log_table.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: log_table table and associated items
*
* Language         - Oracle SQL*Plus script
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 1997
*
*****************************************************************************/
/****************************************************************************
* @(#)$Workfile:   log_table.sql  $  $Revision:   1.3  $
*
* 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/log_table.svl  $
 * 
 *    Rev 1.3   21 Jun 2001 14:47:58   tagtrak
 * OR:
 * CR:
 * Re-baseline version 4.0.0 to include patches.
 * 
 *    Rev 1.2   02 Apr 1998 19:43:24   tagtrak
 * OR:
 * CR:
 * REV:
 * Initial Issue
 * See label for concession
 * 
 *    Rev 1.1   26 Feb 1998 13:59:04   tagtrak
 * OR:
 * CR:
 * REV:
 * Initial core product version
 * 
 *    Rev 1.0.1.1   26 Feb 1998 11:08:06   tagtrak
 * OR:
 * CR:
 * REV:
 * Initial core product version
 * 
 *    Rev 1.0.1.0   29 Jan 1998 13:38:16   tagtrak
 * Added category field to rationalise use of this
 * table for logging many other table changes.
 * 
 *    Rev 1.0   22 Oct 1997 11:08:04   tagtrak
 * OR:
 * CR:
 * REV:
 * Initial check-in
*
****************************************************************************/

PROMPT Creating table LOG_TABLE

create table log_table (
   user_id                       number(10),
   log_time                      date              not null,
   reason                        varchar2(250)     not null,
   record_id                     number(10)        not null,
   category                      varchar2(40),
   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 log_table add ( constraint log_table_pk primary key (appn_row_id) using index tablespace &1._indexes);

alter table log_table add ( constraint log_table_fk_tagtrak_users foreign key (user_id) references tagtrak_users (user_id));

create index LOG_TABLE_SK1 on LOG_TABLE(LOG_TIME) tablespace &1._indexes;
 
create index LOG_TABLE_SK2 on LOG_TABLE(RECORD_ID) tablespace &1._indexes;

create index LOG_TABLE_SK3 on LOG_TABLE(category) tablespace &1._indexes;

CREATE INDEX log_table_sk4 ON log_table(user_id) TABLESPACE &1._indexes;

COMMENT ON TABLE LOG_TABLE IS 'This table contains logs raised by the application';

COMMENT ON COLUMN LOG_TABLE.CATEGORY IS  'Log category';
COMMENT ON COLUMN LOG_TABLE.LOG_TIME IS  'TIme the log was raised';
COMMENT ON COLUMN LOG_TABLE.REASON IS  'Reason for raising the log';
COMMENT ON COLUMN LOG_TABLE.RECORD_ID IS  'Unique identifier';
COMMENT ON COLUMN LOG_TABLE.USER_ID IS  'User identifier';
COMMENT ON COLUMN LOG_TABLE.APPN_ROW_ID IS 'Unique sequence number for this row';
COMMENT ON COLUMN LOG_TABLE.ROW_CREATE_TIME IS 'The time the row was created';
COMMENT ON COLUMN LOG_TABLE.ROW_DATE_TIME IS 'The time the row was last modified';
COMMENT ON COLUMN LOG_TABLE.CUSER IS 'The user who created the row';
COMMENT ON COLUMN LOG_TABLE.MUSER IS 'The user who last modified the row';
COMMENT ON COLUMN LOG_TABLE.MTERM IS 'The terminal from which the last modifcation to this row was made';
COMMENT ON COLUMN LOG_TABLE.SYSTEM_ID IS 'The system identifier';
COMMENT ON COLUMN LOG_TABLE.SOURCE IS 'The process that last amended this row ';
COMMENT ON COLUMN LOG_TABLE.TO_BE_ARCHIVED IS 'Indicates that this row is to be archived or has been archived';
