DEFINE tbl_data = dwhdata
DEFINE tbl_idx  = dwhindex
DEFINE tiny     = 'initial 32K next 64K pctincrease 0'
DEFINE small    = 'initial 64K next 128K pctincrease 0'
DEFINE normal   = 'initial 512K next 2M pctincrease 0'
DEFINE large    = 'initial 2M next 16M pctincrease 0'

PROMPT creating table prm_sys_reference

-- Create table
CREATE TABLE prm_system
(
    paramid         VARCHAR2(30)    NOT NULL,
    paramdesc       VARCHAR2(100)   NOT NULL,
    paramvalue      VARCHAR2(255)   NOT NULL,
	paramtype       VARCHAR2(1)     NOT NULL,
    updateable      VARCHAR2(1)     NOT NULL,
    user_update     VARCHAR2(10)    NOT NULL,
    tgl_update      DATE            NOT NULL,
    flag_oto        VARCHAR2(1)     NULL,
    user_oto        VARCHAR2(10)    NULL,
    tgl_oto         DATE            NULL
)
TABLESPACE &tbl_data
STORAGE (&tiny)
/

ALTER TABLE prm_system
  ADD ( CONSTRAINT pk_prm_system PRIMARY KEY (paramid)
    USING INDEX 
      TABLESPACE &tbl_idx
      STORAGE (&tiny))
/
COMMENT ON TABLE prm_system IS
   'CATEGORY=SYSTEM^NAME=Tabel System Parameter^';


CREATE TABLE prm_sys_reference
(
    tab_name            VARCHAR2(32)        NOT NULL,
    col_name            VARCHAR2(32)        NOT NULL,
    tab_name_ref        VARCHAR2(32)        NOT NULL,
    col_name_ref        VARCHAR2(32)        NOT NULL
)
TABLESPACE &tbl_data
STORAGE (&tiny)
/
ALTER TABLE prm_sys_reference
   ADD ( CONSTRAINT pk_prm_sys_reference PRIMARY KEY (tab_name, col_name)
      USING INDEX
      TABLESPACE &tbl_idx
      STORAGE (&tiny))
/

COMMENT ON TABLE prm_sys_reference IS
   'CATEGORY=SYSTEM^NAME=Tabel Column Reference^';


PROMPT creating table prm_view_reference

CREATE TABLE prm_view_reference
(
    view_name           VARCHAR2(32)        NOT NULL,
    tab_name_ref        VARCHAR2(32)        NOT NULL
)
TABLESPACE &tbl_data
STORAGE (&tiny)
/
ALTER TABLE prm_view_reference
   ADD ( CONSTRAINT pk_prm_view_reference PRIMARY KEY (view_name)
      USING INDEX
      TABLESPACE &tbl_idx
      STORAGE (&tiny))
/
COMMENT ON TABLE prm_view_reference IS
   'CATEGORY=SYSTEM^NAME=Tabel View Reference^';


PROMPT creating table audit_session

CREATE TABLE audit_session
(
    kd_user             VARCHAR2(10)        NOT NULL,
    login_date          DATE                NOT NULL,
    ip_address          VARCHAR2(20)        NOT NULL
)
TABLESPACE &tbl_data
STORAGE (&normal)
/
ALTER TABLE audit_session
   ADD ( CONSTRAINT pk_audit_session PRIMARY KEY (kd_user, login_date)
      USING INDEX
      TABLESPACE &tbl_idx
      STORAGE (&normal))
/
COMMENT ON TABLE audit_session IS
   'CATEGORY=SYSTEM^NAME=Tabel Audit Session^';


PROMPT creating table audittrail

CREATE TABLE audittrail
(
    nourut              NUMBER              NOT NULL,
    tglaudit            DATE                NOT NULL,
    kd_user             VARCHAR2(10)        NOT NULL,
    ipnum               VARCHAR2(30)        NOT NULL,
    pagename            VARCHAR2(50)        NOT NULL,
    activity            VARCHAR2(100)       NOT NULL,
    oldvalue            CLOB                NULL,
    newvalue            CLOB                NULL,
    keterangan          VARCHAR2(1000)      NULL,
    group_data          VARCHAR2(30)        NULL
)
TABLESPACE &tbl_data
STORAGE (&large)
/
ALTER TABLE audittrail
   ADD ( CONSTRAINT pk_audittrail PRIMARY KEY (nourut)
      USING INDEX
      TABLESPACE &tbl_idx
      STORAGE (&large))
/

CREATE INDEX audittrail1_ix 
    ON audittrail (group_data, tglaudit)
    TABLESPACE &tbl_idx
    STORAGE (&large)
/
COMMENT ON TABLE audittrail IS
   'CATEGORY=SYSTEM^NAME=Tabel Audit Trail^';

CREATE TABLE auditparam
(
    param_id            VARCHAR2(10)        NOT NULL,
    keterangan          VARCHAR2(30)        NOT NULL
)    
TABLESPACE &tbl_data
STORAGE (&tiny)
/
ALTER TABLE auditparam
   ADD ( CONSTRAINT pk_auditparam PRIMARY KEY (param_id)
      USING INDEX
      TABLESPACE &tbl_idx
      STORAGE (&tiny))
/
COMMENT ON TABLE auditparam IS
   'CATEGORY=SYSTEM^NAME=Tabel Parameter Audit Trail^';


PROMPT creating table session_tracker

CREATE TABLE session_tracker
(
    session_originator      VARCHAR2(100)   NOT NULL,
    kd_user                 VARCHAR2(10)    NOT NULL,
    nama_user               VARCHAR2(100)   NOT NULL,
    kd_level                VARCHAR2(3)     NOT NULL,
    kd_status               VARCHAR2(1)     NOT NULL,
    last_login              DATE            NULL
)
TABLESPACE &tbl_data
STORAGE (&normal)
/
ALTER TABLE session_tracker
   ADD ( CONSTRAINT pk_session_tracker PRIMARY KEY (session_originator, kd_user)
      USING INDEX
      TABLESPACE &tbl_idx
      STORAGE (&normal))
/
COMMENT ON TABLE session_tracker IS
   'CATEGORY=SYSTEM^NAME=Tabel Session Tracker^';


PROMPT creating table rep_archive

CREATE TABLE rep_archive
(
	kd_user        		VARCHAR2(10) 		NOT NULL,
	n_resultkey    		NUMBER 				NOT NULL,
	date_created   		DATE 				NOT NULL,
	rep_id         		VARCHAR2(20) 		NOT NULL,
	rep_name       		VARCHAR2(500) 		NOT NULL,
	rep_param      		VARCHAR2(4000)		NULL,	
	rep_rows       		NUMBER 				NOT NULL,
	page_rows      		NUMBER 				NOT NULL,
	sum_amount     		NUMBER 				NOT NULL,
	pagename       		VARCHAR2(2000)		NULL,
	rep_header     		VARCHAR2(4000)		NULL,
	item_header    		NUMBER				NULL,
	rep_param_info 		VARCHAR2(4000)		NULL
)
TABLESPACE &tbl_data
STORAGE (&normal)
/
ALTER TABLE rep_archive
   ADD ( CONSTRAINT pk_rep_archive PRIMARY KEY (kd_user, n_resultkey)
      USING INDEX
      TABLESPACE &tbl_idx
      STORAGE (&normal))
/
COMMENT ON TABLE rep_archive IS
   'CATEGORY=REPORT^NAME=Tabel Archive Report^';


PROMPT creating table rep_info

CREATE TABLE rep_info
(
    kd_user             VARCHAR2(10)        NOT NULL,
    n_resultkey         NUMBER              NOT NULL,
    n_rowno             NUMBER              NOT NULL,
    date_created        DATE                NOT NULL,
    rep_content         clob                NULL,
    rep_flag            VARCHAR2(1)         NULL
)
TABLESPACE &tbl_data 
STORAGE(initial 2M next 2M maxextents unlimited pctincrease 0)
/
ALTER TABLE rep_info 
ADD ( CONSTRAINT pk_rep_info PRIMARY KEY (kd_user, n_resultkey, n_rowno)
   USING INDEX TABLESPACE &tbl_idx
      STORAGE (initial 1M
         next 2M
         pctincrease 0
         maxextents unlimited ))
/
COMMENT ON TABLE rep_info IS
   'CATEGORY=REPORT^NAME=Tabel Report^';


PROMPT creating table temp_otorisasi

CREATE TABLE temp_otorisasi
(
    tab_name            VARCHAR2(32)        NOT NULL,
    temp_key            NUMBER              NOT NULL,
    temp_value          VARCHAR2(4000)      NOT NULL,
    dml_status          VARCHAR2(1)         NOT NULL,
    status_data         VARCHAR2(1)         NOT NULL,
    user_oto            VARCHAR2(10)        NULL,
    tgl_oto             DATE                NULL,
    user_update         VARCHAR2(10)        NOT NULL,
    tgl_update          DATE                NOT NULL
)
TABLESPACE &tbl_data
STORAGE (&normal)
/
ALTER TABLE temp_otorisasi
   ADD ( CONSTRAINT pk_temp_otorisasi PRIMARY KEY (tab_name, temp_key)
      USING INDEX
      TABLESPACE &tbl_idx
      STORAGE (&normal))
/
COMMENT ON TABLE temp_otorisasi IS
   'CATEGORY=SYSTEM^NAME=Tabel Otorisasi^';

PROMPT creating table transaction_id_tab

CREATE TABLE transaction_id_tab (
	process_id       	VARCHAR2(2)		not null,
	process_name	 	VARCHAR2(100)   not null,
	process_interval 	VARCHAR2(1)     not null,
	process_desc		VARCHAR2(100)   not null
)
TABLESPACE &tbl_data
STORAGE (&small)
/
ALTER TABLE transaction_id_tab
	ADD ( 
		CONSTRAINT pk_transaction_id_tab PRIMARY KEY ( process_id )
		USING INDEX
			TABLESPACE &tbl_idx
			STORAGE (&small))
/

COMMENT ON TABLE transaction_id_tab IS
   'CATEGORY=SYSTEM^NAME=Tabel Parameter Background Proses^';

PROMPT creating table transaction_job_tab

CREATE TABLE transaction_job_tab (
   job_id 			NUMBER				not null,
   process_id       VARCHAR2(2)			not null,
   user_posting		VARCHAR2(10)		not null,
   date_posting     DATE                not null,
   ipnum            VARCHAR2(30)        NOT NULL,
   status           NUMBER              not null,
   date_finished	DATE				null
)
TABLESPACE &tbl_data
STORAGE (&large)
/
ALTER TABLE transaction_job_tab
	ADD ( 
		CONSTRAINT pk_transaction_job PRIMARY KEY ( job_id )
		USING INDEX
			TABLESPACE &tbl_idx
			STORAGE (&large))
/
CREATE INDEX ix_transaction_job 
	ON transaction_job_tab (user_posting, date_posting, job_id)
		TABLESPACE &tbl_idx
		STORAGE (&large)
/

COMMENT ON TABLE transaction_job_tab IS
   'CATEGORY=SYSTEM^NAME=Tabel Background Proses^';