--Author: Venkata Potluri
--Date: April 04, 2015

/***CREATE TABLE SIEBEL_PURGE.PURGE_CONFIG
(
   ROW_ID               NUMBER,
   PURGE_DATE           DATE,
   PRODUCT_NAME         VARCHAR2 (100 CHAR),
   PROD_ROW_ID          VARCHAR2 (15 CHAR),
   PROD_INT_ID          VARCHAR2 (30 CHAR),
   NET_ATTRIB_DEFN_ID   VARCHAR2 (15 CHAR),
   PARTITION_NAME       VARCHAR2 (50 CHAR),
   OKAY_TO_RUN          CHAR (1 CHAR) DEFAULT 'Y' NOT NULL,
   PRIMARY KEY (ROW_ID, PURGE_DATE)
      USING INDEX
         (CREATE INDEX SIEBEL_PURGE.PURGE_CONFIG_P1
             ON SIEBEL_PURGE.PURGE_CONFIG (ROW_ID, PURGE_DATE))
);

CREATE UNIQUE INDEX SIEBEL_PURGE.PURGE_CONFIG_U1
   ON SIEBEL_PURGE.PURGE_CONFIG (ROW_ID, OKAY_TO_RUN);

GRANT SELECT ON SIEBEL_PURGE.PURGE_CONFIG TO PURGE_RO_ROLE;
GRANT SELECT ON SIEBEL_PURGE.PURGE_CONFIG TO AMP;**/
-----------------------------------------------------

CREATE TABLE SIEBEL_PURGE.PURGE_LOG
(
   ROW_ID           NUMBER,
   PROCESS_NAME     VARCHAR2 (100 CHAR),
   START_TIME       DATE,
   END_TIME         DATE,
   PROCESSED_ROWS   NUMBER,
   PRIMARY KEY (ROW_ID)
      USING INDEX
         (CREATE INDEX SIEBEL_PURGE.PURGE_LOG_P1
             ON SIEBEL_PURGE.PURGE_LOG (ROW_ID))
);

GRANT SELECT ON SIEBEL_PURGE.PURGE_LOG TO PURGE_RO_ROLE;
-----------------------------------------------------

CREATE TABLE SIEBEL_PURGE.PURGE_MEM_TXN
(
   MEMBER_ID            VARCHAR2 (15 CHAR),
   MEM_NUM              VARCHAR2 (30 CHAR),
   PERSON_UID           VARCHAR2 (100 CHAR),
   PURGE_TXN_COUNT      NUMBER,
   ACRL_SUM             NUMBER,
   USED_SUM             NUMBER,
   RDM_SUM              NUMBER,
   SUMMARY_NUM_POINTS   NUMBER,
   SUMMARY_USED_VALUE   NUMBER,
   TXN_NUM              VARCHAR2 (30 CHAR),
   ITEM_NUM             VARCHAR2 (30 CHAR),
   UPDATED_FLG          CHAR (1 CHAR),
   PRIMARY KEY (MEMBER_ID)
      USING INDEX
         (CREATE INDEX SIEBEL_PURGE.PURGE_MEM_TXN_P1
             ON SIEBEL_PURGE.PURGE_MEM_TXN (MEMBER_ID))
);

GRANT SELECT ON SIEBEL_PURGE.PURGE_MEM_TXN TO PURGE_RO_ROLE;

CREATE INDEX SIEBEL_PURGE.PURGE_MEM_TXN_150819B
   ON SIEBEL_PURGE.PURGE_MEM_TXN (MEMBER_ID, UPDATED_FLG);

-----------------------------------------------------

CREATE TABLE SIEBEL_PURGE.PURGE_MEM_REDEEMABLE
(
   MEMBER_ID                   VARCHAR2 (15 CHAR),
   MEM_NUM                     VARCHAR2 (30 CHAR),
   MEM_AVAIL_POINTS            NUMBER,
   PRE_ACRL_SUM                NUMBER,
   PRE_USED_SUM                NUMBER,
   PRE_RDM_SUM                 NUMBER,
   TXN_REDMBLE_PTS_PREPURGE    NUMBER,
   POST_ACRL_SUM               NUMBER,
   POST_USED_SUM               NUMBER,
   POST_RDM_SUM                NUMBER,
   TXN_REDMBLE_PTS_POSTPURGE   NUMBER,
   UPDATED_FLG                 CHAR (1 CHAR),
   PRIMARY KEY (MEMBER_ID)
      USING INDEX
         (CREATE INDEX SIEBEL_PURGE.PURGE_MEM_REDEEMABLE_P1
             ON SIEBEL_PURGE.PURGE_MEM_REDEEMABLE (MEMBER_ID))
);

GRANT SELECT ON SIEBEL_PURGE.PURGE_MEM_REDEEMABLE TO PURGE_RO_ROLE;

CREATE INDEX SIEBEL_PURGE.PURGE_MEM_REDEEMABLE_150819F
   ON SIEBEL_PURGE.PURGE_MEM_REDEEMABLE (UPDATED_FLG, MEMBER_ID);

-----------------------------------------------------

CREATE TABLE SIEBEL_PURGE.PURGE_MEM_INFO
(
   MEMBER_ID                 VARCHAR2 (15 CHAR),
   MEM_NUM                   VARCHAR2 (30 CHAR),
   PRE_LAST_TXN_PROCED_DT    DATE,
   PRE_LAST_ACCR_TXN_DT      DATE,
   PRE_LAST_RDM_TXN_DT       DATE,
   PRE_POINT_TYPE_A_VAL      NUMBER,
   PRE_POINT_TYPE_B_VAL      NUMBER,
   PRE_POINT_TYPE_C_VAL      NUMBER,
   PRE_POINT_TYPE_D_VAL      NUMBER,
   PRE_POINT_TYPE_E_VAL      NUMBER,
   PRE_POINT_TYPE_F_VAL      NUMBER,
   PRE_POINT_TYPE_G_VAL      NUMBER,
   PRE_POINT_TYPE_H_VAL      NUMBER,
   PRE_POINT_TYPE_I_VAL      NUMBER,
   PRE_POINT_TYPE_J_VAL      NUMBER,
   POST_LAST_TXN_PROCED_DT   DATE,
   POST_LAST_ACCR_TXN_DT     DATE,
   POST_LAST_RDM_TXN_DT      DATE,
   POST_POINT_TYPE_A_VAL     NUMBER,
   POST_POINT_TYPE_B_VAL     NUMBER,
   POST_POINT_TYPE_C_VAL     NUMBER,
   POST_POINT_TYPE_D_VAL     NUMBER,
   POST_POINT_TYPE_E_VAL     NUMBER,
   POST_POINT_TYPE_F_VAL     NUMBER,
   POST_POINT_TYPE_G_VAL     NUMBER,
   POST_POINT_TYPE_H_VAL     NUMBER,
   POST_POINT_TYPE_I_VAL     NUMBER,
   POST_POINT_TYPE_J_VAL     NUMBER,
   UPDATED_FLG               CHAR (1 CHAR),
   PRIMARY KEY (MEMBER_ID)
      USING INDEX
         (CREATE INDEX SIEBEL_PURGE.PURGE_MEM_INFO_P1
             ON SIEBEL_PURGE.PURGE_MEM_INFO (MEMBER_ID))
);

GRANT SELECT ON SIEBEL_PURGE.PURGE_MEM_INFO TO PURGE_RO_ROLE;
-----------------------------------------------------

CREATE TABLE SIEBEL_PURGE.TEMP_TXN_MEM
(
   TXN_ID     VARCHAR2 (15 CHAR) NOT NULL,
   T_MEM_ID   VARCHAR2 (15 CHAR)
);

GRANT SELECT ON SIEBEL_PURGE.TEMP_TXN_MEM TO PURGE_RO_ROLE;
-----------------------------------------------------

CREATE TABLE SIEBEL_PURGE.FIX_ACRL_MEM_ID
(
   TXN_ID     VARCHAR2 (15 CHAR),
   T_MEM_ID   VARCHAR2 (15 CHAR),
   ACRL_ID    VARCHAR2 (15 CHAR),
   A_MEM_ID   VARCHAR2 (15 CHAR),
   PRIMARY KEY (ACRL_ID)
      USING INDEX
         (CREATE INDEX SIEBEL_PURGE.FIX_ACRL_MEM_ID_P1
             ON SIEBEL_PURGE.FIX_ACRL_MEM_ID (ACRL_ID))
);

GRANT SELECT ON SIEBEL_PURGE.FIX_ACRL_MEM_ID TO PURGE_RO_ROLE;
-----------------------------------------------------

CREATE TABLE SIEBEL_PURGE.FIX_REDM_MEM_ID
(
   TXN_ID     VARCHAR2 (15 CHAR),
   T_MEM_ID   VARCHAR2 (15 CHAR),
   REDM_ID    VARCHAR2 (15 CHAR),
   R_MEM_ID   VARCHAR2 (15 CHAR),
   PRIMARY KEY (REDM_ID)
      USING INDEX
         (CREATE INDEX SIEBEL_PURGE.FIX_REDM_MEM_ID_P1
             ON SIEBEL_PURGE.FIX_REDM_MEM_ID (REDM_ID))
);

GRANT SELECT ON SIEBEL_PURGE.FIX_REDM_MEM_ID TO PURGE_RO_ROLE;
-----------------------------------------------------

CREATE TABLE SIEBEL_PURGE.TEMP_TXN_XPF
(
   TXN_ID   VARCHAR2 (15 CHAR) NOT NULL
);

GRANT SELECT ON SIEBEL_PURGE.TEMP_TXN_XPF TO PURGE_RO_ROLE;
-----------------------------------------------------

CREATE TABLE SIEBEL_PURGE.P_INT_S_LOY_RDM_ITM
(
   MEM_ID        VARCHAR2 (15 CHAR),
   RDM_ID        VARCHAR2 (15 CHAR),
   PRV_ACRL_ID   VARCHAR2 (15 CHAR),
   NEW_ACRL_ID   VARCHAR2 (15 CHAR),
   ORDER_NUM     NUMBER,
   TASK_NUM      NUMBER,
   PRIMARY KEY (MEM_ID, RDM_ID)
      USING INDEX
         (CREATE INDEX SIEBEL_PURGE.P_INT_S_LOY_RDM_ITM_P1
             ON SIEBEL_PURGE.P_INT_S_LOY_RDM_ITM (MEM_ID, RDM_ID))
);

GRANT SELECT ON SIEBEL_PURGE.P_INT_S_LOY_RDM_ITM TO PURGE_RO_ROLE;
-----------------------------------------------------

CREATE TABLE SIEBEL_PURGE.P_INT_S_LOY_ATTR_ITM
(
   MEM_ID       VARCHAR2 (15 CHAR),
   ATTR_ID      VARCHAR2 (15 CHAR),
   PRV_TXN_ID   VARCHAR2 (15 CHAR),
   NEW_TXN_ID   VARCHAR2 (15 CHAR),
   PRIMARY KEY (MEM_ID, ATTR_ID)
      USING INDEX
         (CREATE INDEX SIEBEL_PURGE.P_INT_S_LOY_ATTR_ITM_P1
             ON SIEBEL_PURGE.P_INT_S_LOY_ATTR_ITM (MEM_ID, ATTR_ID))
);

GRANT SELECT ON SIEBEL_PURGE.P_INT_S_LOY_ATTR_ITM TO PURGE_RO_ROLE;
-----------------------------------------------------

CREATE TABLE SIEBEL_PURGE.P_INT_S_CONTACT_XM
(
   MEM_ID       VARCHAR2 (15 CHAR),
   PMT_ID       VARCHAR2 (15 CHAR),
   PRV_TXN_ID   VARCHAR2 (15 CHAR),
   PRIMARY KEY (PMT_ID)
      USING INDEX
         (CREATE INDEX SIEBEL_PURGE.P_INT_S_CONTACT_XM_P1
             ON SIEBEL_PURGE.P_INT_S_CONTACT_XM (PMT_ID))
);

GRANT SELECT ON SIEBEL_PURGE.P_INT_S_CONTACT_XM TO PURGE_RO_ROLE;
-----------------------------------------------------

CREATE TABLE SIEBEL_PURGE.MEM_MERGE
(
   FROM_MEM_ID     VARCHAR2 (15 CHAR),
   TO_MEM_ID       VARCHAR2 (15 CHAR),
   NEW_MERGE       CHAR (1 CHAR) DEFAULT 'N',
   TO_MEM_EXISTS   CHAR (1 CHAR) DEFAULT 'N',
   PRIMARY KEY (FROM_MEM_ID, TO_MEM_ID)
      USING INDEX
         (CREATE INDEX SIEBEL_PURGE.MEM_MERGE_P1
             ON SIEBEL_PURGE.MEM_MERGE (FROM_MEM_ID, TO_MEM_ID))
);

GRANT SELECT ON SIEBEL_PURGE.MEM_MERGE TO PURGE_RO_ROLE;
-----------------------------------------------------