From 1f55d92191aeef5678686c7031acb8d196fa6fed Mon Sep 17 00:00:00 2001
From: Joao Afonso <joao.afonso@cern.ch>
Date: Tue, 23 Aug 2022 18:21:15 +0200
Subject: [PATCH] Add postgres 10.0 to 11.0 liquibase Schema migration script

---
 .../liquibase/postgres/10.0to11.0.sql         | 42 +++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 catalogue/migrations/liquibase/postgres/10.0to11.0.sql

diff --git a/catalogue/migrations/liquibase/postgres/10.0to11.0.sql b/catalogue/migrations/liquibase/postgres/10.0to11.0.sql
new file mode 100644
index 0000000000..d421d27e16
--- /dev/null
+++ b/catalogue/migrations/liquibase/postgres/10.0to11.0.sql
@@ -0,0 +1,42 @@
+--liquibase formatted sql
+
+--changeset afonso:1 failOnError:true dbms:postgresql
+--preconditions onFail:HALT onError:HALT
+--precondition-sql-check expectedResult:"10.0" SELECT CONCAT(CONCAT(CAST(SCHEMA_VERSION_MAJOR as VARCHAR(10)),'.'), CAST(SCHEMA_VERSION_MINOR AS VARCHAR(10))) AS CATALOGUE_VERSION FROM CTA_CATALOGUE;
+--!!!THIS FALSE PRECONDITION IS HERE TO BLOCK AN UPGRADE WHILE THE DEVELOPMENT OF THE NEW CATALOGUE VERSION IS BEING DEVELOPED!!!
+UPDATE CTA_CATALOGUE SET STATUS='UPGRADING';
+UPDATE CTA_CATALOGUE SET NEXT_SCHEMA_VERSION_MAJOR=11;
+UPDATE CTA_CATALOGUE SET NEXT_SCHEMA_VERSION_MINOR=0;
+--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 afonso:2 failOnError:true dbms:postgresql
+--preconditions onFail:HALT onError:HALT
+--precondition-sql-check expectedResult:"10.0" SELECT CONCAT(CONCAT(CAST(SCHEMA_VERSION_MAJOR as VARCHAR(10)),'.'), CAST(SCHEMA_VERSION_MINOR AS VARCHAR(10))) AS CATALOGUE_VERSION FROM CTA_CATALOGUE;
+ALTER TABLE TAPE DROP CONSTRAINT TAPE_STATE_CK;
+ALTER TABLE TAPE ADD CONSTRAINT TAPE_STATE_CK CHECK(TAPE_STATE IN ('ACTIVE', 'REPACKING_PENDING', 'REPACKING', 'DISABLED', 'BROKEN_PENDING', 'BROKEN'));
+--rollback ALTER TABLE TAPE DROP CONSTRAINT TAPE_STATE_CK;
+--rollback ALTER TABLE TAPE ADD CONSTRAINT TAPE_STATE_CK CHECK(TAPE_STATE IN ('ACTIVE', 'REPACKING', 'DISABLED', 'BROKEN'));
+
+--changeset afonso:3 failOnError:true dbms:postgresql
+--preconditions onFail:HALT onError:HALT
+--precondition-sql-check expectedResult:"10.0" SELECT CONCAT(CONCAT(CAST(SCHEMA_VERSION_MAJOR as VARCHAR(10)),'.'), CAST(SCHEMA_VERSION_MINOR AS VARCHAR(10))) AS CATALOGUE_VERSION FROM CTA_CATALOGUE;
+ALTER TABLE DISK_SYSTEM DROP COLUMN FREE_SPACE_QUERY_URL;
+ALTER TABLE DISK_SYSTEM DROP COLUMN REFRESH_INTERVAL;
+--rollback ALTER TABLE DISK_SYSTEM ADD COLUMN FREE_SPACE_QUERY_URL VARCHAR(1000);
+--rollback ALTER TABLE DISK_SYSTEM ADD COLUMN REFRESH_INTERVAL UINT64TYPE;
+
+--changeset afonso:4 failOnError:true dbms:postgresql
+--preconditions onFail:HALT onError:HALT
+--precondition-sql-check expectedResult:"10.0" 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='PRODUCTION';
+UPDATE CTA_CATALOGUE SET SCHEMA_VERSION_MAJOR=11;
+UPDATE CTA_CATALOGUE SET SCHEMA_VERSION_MINOR=0;
+UPDATE CTA_CATALOGUE SET NEXT_SCHEMA_VERSION_MAJOR=NULL;
+UPDATE CTA_CATALOGUE SET NEXT_SCHEMA_VERSION_MINOR=NULL;
+--rollback UPDATE CTA_CATALOGUE SET STATUS='UPGRADING';
+--rollback UPDATE CTA_CATALOGUE SET SCHEMA_VERSION_MAJOR=10;
+--rollback UPDATE CTA_CATALOGUE SET SCHEMA_VERSION_MINOR=0;
+--rollback UPDATE CTA_CATALOGUE SET NEXT_SCHEMA_VERSION_MAJOR=11;
+--rollback UPDATE CTA_CATALOGUE SET NEXT_SCHEMA_VERSION_MINOR=0;
-- 
GitLab