--liquibase formatted sql

--changeset mvelosob:1 failOnError:true dbms:postgresql
--preconditions onFail:HALT onError:HALT
--precondition-sql-check expectedResult:"4.2" SELECT CONCAT(CONCAT(CAST(SCHEMA_VERSION_MAJOR as VARCHAR(10)),'.'), CAST(SCHEMA_VERSION_MINOR AS VARCHAR(10))) AS CATALOGUE_VERSION FROM CTA_CATALOGUE;
UPDATE CTA_CATALOGUE SET STATUS='UPGRADING';
UPDATE CTA_CATALOGUE SET NEXT_SCHEMA_VERSION_MAJOR=4;
UPDATE CTA_CATALOGUE SET NEXT_SCHEMA_VERSION_MINOR=3;
--rollback UPDATE CTA_CATALOGUE SET NEXT_SCHEMA_VERSION_MAJOR=NULL;
--rollback UPDATE CTA_CATALOGUE SET NEXT_SCHEMA_VERSION_MINOR=NULL;
--rollback UPDATE CTA_CATALOGUE SET STATUS='PRODUCTION';

--changeset mvelosob:2 failOnError:true dbms:postgresql
--preconditions onFail:HALT onError:HALT
--precondition-sql-check expectedResult:"4.2" SELECT CONCAT(CONCAT(CAST(SCHEMA_VERSION_MAJOR as VARCHAR(10)),'.'), CAST(SCHEMA_VERSION_MINOR AS VARCHAR(10))) AS CATALOGUE_VERSION FROM CTA_CATALOGUE;
CREATE TABLE REQUESTER_ACTIVITY_MOUNT_RULE(
	  DISK_INSTANCE_NAME     VARCHAR(100)    CONSTRAINT RQSTER_ACT_RULE_DIN_NN  NOT NULL,
	  REQUESTER_NAME         VARCHAR(100)    CONSTRAINT RQSTER_ACT_RULE_RN_NN   NOT NULL,
	  ACTIVITY_REGEX         VARCHAR(100)    CONSTRAINT RQSTER_ACT_RULE_AR_NN   NOT NULL,
	  MOUNT_POLICY_NAME      VARCHAR(100)    CONSTRAINT RQSTER_ACT_RULE_MPN_NN  NOT NULL,
	  USER_COMMENT           VARCHAR(1000)   CONSTRAINT RQSTER_ACT_RULE_UC_NN   NOT NULL,
	  CREATION_LOG_USER_NAME VARCHAR(100)    CONSTRAINT RQSTER_ACT_RULE_CLUN_NN NOT NULL,
	  CREATION_LOG_HOST_NAME VARCHAR(100)    CONSTRAINT RQSTER_ACT_RULE_CLHN_NN NOT NULL,
	  CREATION_LOG_TIME      NUMERIC(20, 0)      CONSTRAINT RQSTER_ACT_RULE_CLT_NN  NOT NULL,
	  LAST_UPDATE_USER_NAME  VARCHAR(100)    CONSTRAINT RQSTER_ACT_RULE_LUUN_NN NOT NULL,
	  LAST_UPDATE_HOST_NAME  VARCHAR(100)    CONSTRAINT RQSTER_ACT_RULE_LUHN_NN NOT NULL,
	  LAST_UPDATE_TIME       NUMERIC(20, 0)      CONSTRAINT RQSTER_ACT_RULE_LUT_NN  NOT NULL,
	  CONSTRAINT RQSTER_ACT_RULE_PK PRIMARY KEY(DISK_INSTANCE_NAME, REQUESTER_NAME, ACTIVITY_REGEX),
	  CONSTRAINT RQSTER_ACT_RULE_MNT_PLC_FK FOREIGN KEY(MOUNT_POLICY_NAME)
	    REFERENCES MOUNT_POLICY(MOUNT_POLICY_NAME)
);
--rollback DROP TABLE REQUESTER_ACTIVITY_MOUNT_RULE

--changeset mvelosob:3 failOnError:true dbms:postgresql
--preconditions onFail:HALT onError:HALT
--precondition-sql-check expectedResult:"4.2" SELECT CONCAT(CONCAT(CAST(SCHEMA_VERSION_MAJOR as VARCHAR(10)),'.'), CAST(SCHEMA_VERSION_MINOR AS VARCHAR(10))) AS CATALOGUE_VERSION FROM CTA_CATALOGUE;
UPDATE CTA_CATALOGUE SET SCHEMA_VERSION_MAJOR=4;
UPDATE CTA_CATALOGUE SET SCHEMA_VERSION_MINOR=3;
UPDATE CTA_CATALOGUE SET NEXT_SCHEMA_VERSION_MAJOR=NULL;
UPDATE CTA_CATALOGUE SET NEXT_SCHEMA_VERSION_MINOR=NULL;
UPDATE CTA_CATALOGUE SET STATUS='PRODUCTION';
--rollback UPDATE CTA_CATALOGUE SET STATUS='UPGRADING';
--rollback UPDATE CTA_CATALOGUE SET SCHEMA_VERSION_MAJOR=4;
--rollback UPDATE CTA_CATALOGUE SET SCHEMA_VERSION_MINOR=2;
--rollback UPDATE CTA_CATALOGUE SET NEXT_SCHEMA_VERSION_MAJOR=4;
--rollback UPDATE CTA_CATALOGUE SET NEXT_SCHEMA_VERSION_MINOR=3;
