__IF_EXISTS__
SELECT 1
  FROM CI_UT_INSTL_DTL
 WHERE SCRIPT_FILE_NAME = 'FW400_BPSCHEMA5.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_SNDR_CTX'
/
__ELSE__

__EXIT__

__ENDIF__


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

__ELSE__

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


__ENDIF__


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


UPDATE CI_XAI_SNDR_CTX SET F1_CTXT_VAL_LONG = RTRIM(CTXT_VAL)
/

__ENDIF__


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

ALTER TABLE CI_XAI_SNDR_CTX DROP PRIMARY KEY
/


DROP INDEX XC995P0
/

CREATE UNIQUE INDEX XC995P0 ON CI_XAI_SNDR_CTX
(
    XAI_SENDER_ID ASC,
    SENDER_CTXT_FLG ASC,
    F1_CTXT_VAL_LONG ASC
)
/


ALTER TABLE CI_XAI_SNDR_CTX ADD CONSTRAINT XC995P0 PRIMARY KEY
(       XAI_SENDER_ID,
        SENDER_CTXT_FLG,
        F1_CTXT_VAL_LONG
) USING INDEX
/


__ENDIF__


