SELECT 'Upgrading MetaStore schema from 2.0.0 to 2.1.0' AS Status from dual;

--@034-HIVE-13076.oracle.sql;
CREATE TABLE KEY_CONSTRAINTS
(
  CHILD_CD_ID NUMBER,
  CHILD_INTEGER_IDX NUMBER,
  CHILD_TBL_ID NUMBER,
  PARENT_CD_ID NUMBER NOT NULL,
  PARENT_INTEGER_IDX NUMBER NOT NULL,
  PARENT_TBL_ID NUMBER NOT NULL,
  POSITION NUMBER NOT NULL,
  CONSTRAINT_NAME VARCHAR(400) NOT NULL,
  CONSTRAINT_TYPE NUMBER NOT NULL,
  UPDATE_RULE NUMBER,
  DELETE_RULE NUMBER,
  ENABLE_VALIDATE_RELY NUMBER NOT NULL
) ;
ALTER TABLE KEY_CONSTRAINTS ADD CONSTRAINT CONSTRAINTS_PK PRIMARY KEY (CONSTRAINT_NAME, POSITION);
CREATE INDEX CONSTRAINTS_PT_INDEX ON KEY_CONSTRAINTS(PARENT_TBL_ID);

--@035-HIVE-13395.oracle.sql;
CREATE TABLE WRITE_SET (
  WS_DATABASE varchar2(128) NOT NULL,
  WS_TABLE varchar2(128) NOT NULL,
  WS_PARTITION varchar2(767),
  WS_TXNID number(19) NOT NULL,
  WS_COMMIT_ID number(19) NOT NULL,
  WS_OPERATION_TYPE char(1) NOT NULL
);

ALTER TABLE TXN_COMPONENTS ADD TC_OPERATION_TYPE char(1);

--@036-HIVE-13354.oracle.sql;
ALTER TABLE COMPACTION_QUEUE ADD CQ_TBLPROPERTIES varchar(2048);
ALTER TABLE COMPLETED_COMPACTIONS ADD CC_TBLPROPERTIES varchar(2048);

UPDATE VERSION SET SCHEMA_VERSION='2.1.0', VERSION_COMMENT='Hive release version 2.1.0' where VER_ID=1;
SELECT 'Finished upgrading MetaStore schema from 2.0.0 to 2.1.0' AS Status from dual;
