__IF_EXISTS__
SELECT 1
  FROM CI_UT_INSTL_DTL
 WHERE SCRIPT_FILE_NAME = 'FW42020_BPSCHEMA1.SQL'
   AND END_DTTM IS NOT NULL
/
__THEN__

__EXIT__

__ENDIF__

__IF_EXISTS__
SELECT 1
  FROM USER_TABLES
 WHERE TABLE_NAME = 'F1_INSTALLATION'
/
__ELSE__

__EXIT__

__ENDIF__

__IF_EXISTS__
SELECT 1
  FROM USER_TABLES
 WHERE TABLE_NAME = 'CI_XAI_RCVR_CTX'
/
__ELSE__

__EXIT__

__ENDIF__


__IF_EXISTS__
SELECT 1
  FROM USER_TAB_COLUMNS
 WHERE TABLE_NAME = 'CI_XAI_RCVR_CTX'
   AND COLUMN_NAME = 'F1_CTXT_VAL_LONG'
/

__ELSE__

ALTER TABLE CI_XAI_RCVR_CTX ADD
(
    F1_CTXT_VAL_LONG  VARCHAR2(4000) NULL 
)
/


__ENDIF__


__IF_EXISTS__
SELECT 1
  FROM USER_TAB_COLUMNS
 WHERE TABLE_NAME = 'CI_XAI_RCVR_CTX'
   AND COLUMN_NAME = 'CTXT_VAL'
/
__THEN__


UPDATE CI_XAI_RCVR_CTX SET F1_CTXT_VAL_LONG = RTRIM(CTXT_VAL)
/

ALTER TABLE CI_XAI_RCVR_CTX MODIFY (CTXT_VAL NULL)
/

__ENDIF__


__IF_EXISTS__
SELECT 1
  FROM USER_CONSTRAINTS
 WHERE TABLE_NAME = 'CI_XAI_RCVR_CTX'
   AND CONSTRAINT_TYPE = 'P'
/
__THEN__

ALTER TABLE CI_XAI_RCVR_CTX DROP PRIMARY KEY
/


DROP INDEX XC981P0
/

CREATE UNIQUE INDEX XC981P0 ON CI_XAI_RCVR_CTX
(
    XAI_RCVR_ID ASC,
    RCVR_CTXT_FLG ASC,
    F1_CTXT_VAL_LONG ASC
)
/


ALTER TABLE CI_XAI_RCVR_CTX ADD CONSTRAINT XC981P0 PRIMARY KEY
(       XAI_RCVR_ID,
        RCVR_CTXT_FLG,
        F1_CTXT_VAL_LONG
) USING INDEX
/


__ENDIF__


