From fdfcf5e484c8d6aa8e6555624b54cc63dba94fb6 Mon Sep 17 00:00:00 2001
From: Cedric CAFFY <cedric.caffy@cern.ch>
Date: Tue, 21 Jan 2020 17:51:17 +0100
Subject: [PATCH] Added DEFERRED constraint for CTA_CATALOGUE table

Added SchemaMetadataGetter class in order to filter the database-metadata content returned by the SQLite schema we use to check the Catalogue database
Example: for Postgres, we cannot get the NOT NULL constraint names, so we filter these constraint names from the SQLite database in order to
not display that the Postgres catalogue has missing NOT NULL constraints
---
 catalogue/1.1/mysql_catalogue_schema.sql      |  3 +-
 catalogue/1.1/oracle_catalogue_schema.sql     |  5 +-
 catalogue/1.1/postgres_catalogue_schema.sql   |  3 +-
 catalogue/1.1/sqlite_catalogue_schema.sql     |  3 +-
 catalogue/AllCatalogueSchema.hpp              | 14 +++--
 catalogue/CatalogueMetadataGetter.cpp         | 52 ++++++++++++++-----
 catalogue/CatalogueMetadataGetter.hpp         | 47 ++++++++++++-----
 catalogue/SQLiteSchemaComparer.cpp            | 14 +++--
 catalogue/SQLiteSchemaComparer.hpp            |  2 +-
 catalogue/common_catalogue_schema.sql         |  3 +-
 .../migrations/liquibase/oracle/1.0to1.1.sql  |  2 +-
 catalogue/oracle_catalogue_schema_trailer.sql |  2 +
 12 files changed, 100 insertions(+), 50 deletions(-)

diff --git a/catalogue/1.1/mysql_catalogue_schema.sql b/catalogue/1.1/mysql_catalogue_schema.sql
index 458adb65e7..ba96bfbb6c 100644
--- a/catalogue/1.1/mysql_catalogue_schema.sql
+++ b/catalogue/1.1/mysql_catalogue_schema.sql
@@ -24,8 +24,7 @@ CREATE TABLE CTA_CATALOGUE(
   SCHEMA_VERSION_MINOR    BIGINT UNSIGNED      CONSTRAINT CTA_CATALOGUE_SVM2_NN NOT NULL,
   NEXT_SCHEMA_VERSION_MAJOR BIGINT UNSIGNED,
   NEXT_SCHEMA_VERSION_MINOR BIGINT UNSIGNED,
-  STATUS                  VARCHAR(100),
-  CONSTRAINT CATALOGUE_STATUS_CONTENT_CK CHECK((NEXT_SCHEMA_VERSION_MAJOR IS NULL AND NEXT_SCHEMA_VERSION_MINOR IS NULL AND STATUS='COMPLETE') OR (STATUS='UPGRADING'))
+  STATUS                  VARCHAR(100)
 );
 CREATE TABLE ADMIN_USER(
   ADMIN_USER_NAME         VARCHAR(100)    CONSTRAINT ADMIN_USER_AUN_NN  NOT NULL,
diff --git a/catalogue/1.1/oracle_catalogue_schema.sql b/catalogue/1.1/oracle_catalogue_schema.sql
index 424304fd44..14e458c836 100644
--- a/catalogue/1.1/oracle_catalogue_schema.sql
+++ b/catalogue/1.1/oracle_catalogue_schema.sql
@@ -46,8 +46,7 @@ CREATE TABLE CTA_CATALOGUE(
   SCHEMA_VERSION_MINOR    NUMERIC(20, 0)      CONSTRAINT CTA_CATALOGUE_SVM2_NN NOT NULL,
   NEXT_SCHEMA_VERSION_MAJOR NUMERIC(20, 0),
   NEXT_SCHEMA_VERSION_MINOR NUMERIC(20, 0),
-  STATUS                  VARCHAR2(100),
-  CONSTRAINT CATALOGUE_STATUS_CONTENT_CK CHECK((NEXT_SCHEMA_VERSION_MAJOR IS NULL AND NEXT_SCHEMA_VERSION_MINOR IS NULL AND STATUS='COMPLETE') OR (STATUS='UPGRADING'))
+  STATUS                  VARCHAR2(100)
 );
 CREATE TABLE ADMIN_USER(
   ADMIN_USER_NAME         VARCHAR2(100)    CONSTRAINT ADMIN_USER_AUN_NN  NOT NULL,
@@ -315,4 +314,6 @@ INSERT INTO CTA_CATALOGUE(
 VALUES(
   1,
   1);
+ALTER TABLE CTA_CATALOGUE ADD CONSTRAINT CATALOGUE_STATUS_CONTENT_CK CHECK((NEXT_SCHEMA_VERSION_MAJOR IS NULL AND NEXT_SCHEMA_VERSION_MINOR IS NULL AND STATUS='COMPLETE') OR (NEXT_SCHEMA_VERSION_MAJOR IS NOT NULL AND NEXT_SCHEMA_VERSION_MINOR IS NOT NULL AND STATUS='UPGRADING')) INITIALLY DEFERRED;
+
 COMMIT;
diff --git a/catalogue/1.1/postgres_catalogue_schema.sql b/catalogue/1.1/postgres_catalogue_schema.sql
index 45441bcbfb..662305e2cd 100644
--- a/catalogue/1.1/postgres_catalogue_schema.sql
+++ b/catalogue/1.1/postgres_catalogue_schema.sql
@@ -31,8 +31,7 @@ CREATE TABLE CTA_CATALOGUE(
   SCHEMA_VERSION_MINOR    NUMERIC(20, 0)      CONSTRAINT CTA_CATALOGUE_SVM2_NN NOT NULL,
   NEXT_SCHEMA_VERSION_MAJOR NUMERIC(20, 0),
   NEXT_SCHEMA_VERSION_MINOR NUMERIC(20, 0),
-  STATUS                  VARCHAR(100),
-  CONSTRAINT CATALOGUE_STATUS_CONTENT_CK CHECK((NEXT_SCHEMA_VERSION_MAJOR IS NULL AND NEXT_SCHEMA_VERSION_MINOR IS NULL AND STATUS='COMPLETE') OR (STATUS='UPGRADING'))
+  STATUS                  VARCHAR(100)
 );
 CREATE TABLE ADMIN_USER(
   ADMIN_USER_NAME         VARCHAR(100)    CONSTRAINT ADMIN_USER_AUN_NN  NOT NULL,
diff --git a/catalogue/1.1/sqlite_catalogue_schema.sql b/catalogue/1.1/sqlite_catalogue_schema.sql
index d900684cbf..b730593c34 100644
--- a/catalogue/1.1/sqlite_catalogue_schema.sql
+++ b/catalogue/1.1/sqlite_catalogue_schema.sql
@@ -15,8 +15,7 @@ CREATE TABLE CTA_CATALOGUE(
   SCHEMA_VERSION_MINOR    INTEGER      CONSTRAINT CTA_CATALOGUE_SVM2_NN NOT NULL,
   NEXT_SCHEMA_VERSION_MAJOR INTEGER,
   NEXT_SCHEMA_VERSION_MINOR INTEGER,
-  STATUS                  VARCHAR(100),
-  CONSTRAINT CATALOGUE_STATUS_CONTENT_CK CHECK((NEXT_SCHEMA_VERSION_MAJOR IS NULL AND NEXT_SCHEMA_VERSION_MINOR IS NULL AND STATUS='COMPLETE') OR (STATUS='UPGRADING'))
+  STATUS                  VARCHAR(100)
 );
 CREATE TABLE ADMIN_USER(
   ADMIN_USER_NAME         VARCHAR(100)    CONSTRAINT ADMIN_USER_AUN_NN  NOT NULL,
diff --git a/catalogue/AllCatalogueSchema.hpp b/catalogue/AllCatalogueSchema.hpp
index c6fc101274..d3e567a99b 100644
--- a/catalogue/AllCatalogueSchema.hpp
+++ b/catalogue/AllCatalogueSchema.hpp
@@ -1271,8 +1271,7 @@ namespace catalogue{
   "  SCHEMA_VERSION_MINOR    NUMERIC(20, 0)      CONSTRAINT CTA_CATALOGUE_SVM2_NN NOT NULL,"
   "  NEXT_SCHEMA_VERSION_MAJOR NUMERIC(20, 0),"
   "  NEXT_SCHEMA_VERSION_MINOR NUMERIC(20, 0),"
-  "  STATUS                  VARCHAR2(100),"
-  "  CONSTRAINT CATALOGUE_STATUS_CONTENT_CK CHECK((NEXT_SCHEMA_VERSION_MAJOR IS NULL AND NEXT_SCHEMA_VERSION_MINOR IS NULL AND STATUS='COMPLETE') OR (STATUS='UPGRADING'))"
+  "  STATUS                  VARCHAR2(100)"
   ");"
   "CREATE TABLE ADMIN_USER("
   "  ADMIN_USER_NAME         VARCHAR2(100)    CONSTRAINT ADMIN_USER_AUN_NN  NOT NULL,"
@@ -1540,6 +1539,8 @@ namespace catalogue{
   "VALUES("
   "  1,"
   "  1);"
+  "ALTER TABLE CTA_CATALOGUE ADD CONSTRAINT CATALOGUE_STATUS_CONTENT_CK CHECK((NEXT_SCHEMA_VERSION_MAJOR IS NULL AND NEXT_SCHEMA_VERSION_MINOR IS NULL AND STATUS='COMPLETE') OR (NEXT_SCHEMA_VERSION_MAJOR IS NOT NULL AND NEXT_SCHEMA_VERSION_MINOR IS NOT NULL AND STATUS='UPGRADING')) INITIALLY DEFERRED;"
+  ""
   "COMMIT;"
       },
   {"mysql",  "CREATE TABLE ARCHIVE_FILE_ID("
@@ -1568,8 +1569,7 @@ namespace catalogue{
   "  SCHEMA_VERSION_MINOR    BIGINT UNSIGNED      CONSTRAINT CTA_CATALOGUE_SVM2_NN NOT NULL,"
   "  NEXT_SCHEMA_VERSION_MAJOR BIGINT UNSIGNED,"
   "  NEXT_SCHEMA_VERSION_MINOR BIGINT UNSIGNED,"
-  "  STATUS                  VARCHAR(100),"
-  "  CONSTRAINT CATALOGUE_STATUS_CONTENT_CK CHECK((NEXT_SCHEMA_VERSION_MAJOR IS NULL AND NEXT_SCHEMA_VERSION_MINOR IS NULL AND STATUS='COMPLETE') OR (STATUS='UPGRADING'))"
+  "  STATUS                  VARCHAR(100)"
   ");"
   "CREATE TABLE ADMIN_USER("
   "  ADMIN_USER_NAME         VARCHAR(100)    CONSTRAINT ADMIN_USER_AUN_NN  NOT NULL,"
@@ -1855,8 +1855,7 @@ namespace catalogue{
   "  SCHEMA_VERSION_MINOR    INTEGER      CONSTRAINT CTA_CATALOGUE_SVM2_NN NOT NULL,"
   "  NEXT_SCHEMA_VERSION_MAJOR INTEGER,"
   "  NEXT_SCHEMA_VERSION_MINOR INTEGER,"
-  "  STATUS                  VARCHAR(100),"
-  "  CONSTRAINT CATALOGUE_STATUS_CONTENT_CK CHECK((NEXT_SCHEMA_VERSION_MAJOR IS NULL AND NEXT_SCHEMA_VERSION_MINOR IS NULL AND STATUS='COMPLETE') OR (STATUS='UPGRADING'))"
+  "  STATUS                  VARCHAR(100)"
   ");"
   "CREATE TABLE ADMIN_USER("
   "  ADMIN_USER_NAME         VARCHAR(100)    CONSTRAINT ADMIN_USER_AUN_NN  NOT NULL,"
@@ -2158,8 +2157,7 @@ namespace catalogue{
   "  SCHEMA_VERSION_MINOR    NUMERIC(20, 0)      CONSTRAINT CTA_CATALOGUE_SVM2_NN NOT NULL,"
   "  NEXT_SCHEMA_VERSION_MAJOR NUMERIC(20, 0),"
   "  NEXT_SCHEMA_VERSION_MINOR NUMERIC(20, 0),"
-  "  STATUS                  VARCHAR(100),"
-  "  CONSTRAINT CATALOGUE_STATUS_CONTENT_CK CHECK((NEXT_SCHEMA_VERSION_MAJOR IS NULL AND NEXT_SCHEMA_VERSION_MINOR IS NULL AND STATUS='COMPLETE') OR (STATUS='UPGRADING'))"
+  "  STATUS                  VARCHAR(100)"
   ");"
   "CREATE TABLE ADMIN_USER("
   "  ADMIN_USER_NAME         VARCHAR(100)    CONSTRAINT ADMIN_USER_AUN_NN  NOT NULL,"
diff --git a/catalogue/CatalogueMetadataGetter.cpp b/catalogue/CatalogueMetadataGetter.cpp
index 73ddce624d..ba354d3048 100644
--- a/catalogue/CatalogueMetadataGetter.cpp
+++ b/catalogue/CatalogueMetadataGetter.cpp
@@ -22,7 +22,10 @@
 namespace cta {
 namespace catalogue {
 
-void CatalogueMetadataGetter::removeObjectNameContaining(std::list<std::string>& objects, const std::list<std::string> &wordsToTriggerRemoval){
+  
+MetadataGetter::~MetadataGetter(){}
+  
+void MetadataGetter::removeObjectNameContaining(std::list<std::string>& objects, const std::list<std::string> &wordsToTriggerRemoval){
   objects.remove_if([&wordsToTriggerRemoval](const std::string &object){
     return std::find_if(wordsToTriggerRemoval.begin(), wordsToTriggerRemoval.end(),[&object](const std::string &wordTriggeringRemoval){
       return object.find(wordTriggeringRemoval) != std::string::npos;
@@ -30,7 +33,7 @@ void CatalogueMetadataGetter::removeObjectNameContaining(std::list<std::string>&
   });
 }
 
-void CatalogueMetadataGetter::removeObjectNameNotContaining(std::list<std::string>& objects, const std::list<std::string> &wordsNotToTriggerRemoval){
+void MetadataGetter::removeObjectNameNotContaining(std::list<std::string>& objects, const std::list<std::string> &wordsNotToTriggerRemoval){
   objects.remove_if([&wordsNotToTriggerRemoval](const std::string &object){
     return std::find_if(wordsNotToTriggerRemoval.begin(), wordsNotToTriggerRemoval.end(),[&object](const std::string &wordsNotToTriggeringRemoval){
       return object.find(wordsNotToTriggeringRemoval) == std::string::npos;
@@ -38,13 +41,13 @@ void CatalogueMetadataGetter::removeObjectNameNotContaining(std::list<std::strin
   });
 }
 
-void CatalogueMetadataGetter::removeObjectNameNotMatches(std::list<std::string> &objects, const cta::utils::Regex &regex){
+void MetadataGetter::removeObjectNameNotMatches(std::list<std::string> &objects, const cta::utils::Regex &regex){
   objects.remove_if([&regex](const std::string &object){
     return !regex.has_match(object);
   });
 }
 
-void CatalogueMetadataGetter::removeObjectNameMatches(std::list<std::string> &objects, const cta::utils::Regex &regex){
+void MetadataGetter::removeObjectNameMatches(std::list<std::string> &objects, const cta::utils::Regex &regex){
   objects.remove_if([&regex](const std::string &object){
     return regex.has_match(object);
   });
@@ -93,7 +96,10 @@ std::map<std::string,std::string> CatalogueMetadataGetter::getColumns(const std:
 }
 
 std::list<std::string> CatalogueMetadataGetter::getConstraintNames(const std::string &tableName){
-  return m_conn.getConstraintNames(tableName);
+  std::list<std::string> constraintNames = m_conn.getConstraintNames(tableName);
+  //This constraint is added by ALTER TABLE, we can't check its existence for now
+  removeObjectNameContaining(constraintNames,{"CATALOGUE_STATUS_CONTENT_CK"});
+  return constraintNames;
 }
 
 CatalogueMetadataGetter::~CatalogueMetadataGetter() {}
@@ -115,14 +121,6 @@ std::list<std::string> SQLiteCatalogueMetadataGetter::getTableNames(){
   return tableNames;
 }
 
-std::list<std::string> SQLiteCatalogueMetadataGetter::getConstraintNames(const std::string &tableName, cta::rdbms::Login::DbType dbType){
-  std::list<std::string> constraintNames = CatalogueMetadataGetter::getConstraintNames(tableName);
-  if(dbType == cta::rdbms::Login::DbType::DBTYPE_POSTGRESQL){
-    removeObjectNameMatches(constraintNames,cta::utils::Regex("(^NN_)|(_NN$)"));
-  }
-  return constraintNames;
-}
-
 OracleCatalogueMetadataGetter::OracleCatalogueMetadataGetter(cta::rdbms::Conn & conn):CatalogueMetadataGetter(conn){}
 OracleCatalogueMetadataGetter::~OracleCatalogueMetadataGetter(){}
 
@@ -149,5 +147,33 @@ CatalogueMetadataGetter * CatalogueMetadataGetterFactory::create(const rdbms::Lo
   }
 }
 
+/**
+ * SCHEMA METADATA GETTER methods
+ */
+SchemaMetadataGetter::SchemaMetadataGetter(std::unique_ptr<SQLiteCatalogueMetadataGetter> sqliteCatalogueMetadataGetter, const cta::rdbms::Login::DbType dbType):m_dbType(dbType) {
+  m_sqliteCatalogueMetadataGetter = std::move(sqliteCatalogueMetadataGetter);
+}
+
+std::list<std::string> SchemaMetadataGetter::getIndexNames() {
+  return m_sqliteCatalogueMetadataGetter->getIndexNames();
+}
+
+std::list<std::string> SchemaMetadataGetter::getTableNames() {
+  return m_sqliteCatalogueMetadataGetter->getTableNames();
+}
+
+std::map<std::string,std::string> SchemaMetadataGetter::getColumns(const std::string& tableName) {
+  return m_sqliteCatalogueMetadataGetter->getColumns(tableName);
+}
+
+std::list<std::string> SchemaMetadataGetter::getConstraintNames(const std::string& tableName) {
+  std::list<std::string> constraintNames = m_sqliteCatalogueMetadataGetter->getConstraintNames(tableName);
+  if(m_dbType == cta::rdbms::Login::DbType::DBTYPE_POSTGRESQL){
+    //If the database to compare is POSTGRESQL, we cannot compare NOT NULL CONSTRAINT names
+    //indeed, POSTGRESQL can not give the NOT NULL constraint names
+    removeObjectNameMatches(constraintNames,cta::utils::Regex("(^NN_)|(_NN$)"));
+  }
+  return constraintNames;
+}
 
 }}
\ No newline at end of file
diff --git a/catalogue/CatalogueMetadataGetter.hpp b/catalogue/CatalogueMetadataGetter.hpp
index d2f77567bf..dc8fcd1d9d 100644
--- a/catalogue/CatalogueMetadataGetter.hpp
+++ b/catalogue/CatalogueMetadataGetter.hpp
@@ -25,18 +25,32 @@
 
 namespace cta {
 namespace catalogue {
+  
+/**
+ * Interface class to get database metadata
+ */  
+class MetadataGetter{
+  
+protected:
+  void removeObjectNameContaining(std::list<std::string>& objects, const std::list<std::string> &wordsToTriggerRemoval);
+  void removeObjectNameNotContaining(std::list<std::string>& objects, const std::list<std::string> &wordsNotToTriggerRemoval);
+  void removeObjectNameNotMatches(std::list<std::string> &objects, const cta::utils::Regex &regex);
+  void removeObjectNameMatches(std::list<std::string> &objects, const cta::utils::Regex &regex);
+public:
+  virtual std::list<std::string> getIndexNames() = 0;
+  virtual std::list<std::string> getTableNames() = 0;
+  virtual std::map<std::string,std::string> getColumns(const std::string& tableName) = 0;
+  virtual std::list<std::string> getConstraintNames(const std::string& tableName) = 0;
+  virtual ~MetadataGetter() = 0;
+};
 
 /**
  * This class is used to get the Metadata (table names, columns, indexes) of the database accessed via the connection given in parameters
  * It will simply call the methods from the connection (Conn) instance and adapt or not the metadata returned.  
  */  
-class CatalogueMetadataGetter {
+class CatalogueMetadataGetter: public MetadataGetter {
   protected:
     rdbms::Conn& m_conn;
-    void removeObjectNameContaining(std::list<std::string>& objects, const std::list<std::string> &wordsToTriggerRemoval);
-    void removeObjectNameNotContaining(std::list<std::string>& objects, const std::list<std::string> &wordsNotToTriggerRemoval);
-    void removeObjectNameNotMatches(std::list<std::string> &objects, const cta::utils::Regex &regex);
-    void removeObjectNameMatches(std::list<std::string> &objects, const cta::utils::Regex &regex);
   public:
     CatalogueMetadataGetter(cta::rdbms::Conn & conn);
     virtual ~CatalogueMetadataGetter();
@@ -56,13 +70,6 @@ public:
   virtual ~SQLiteCatalogueMetadataGetter();
   std::list<std::string> getIndexNames() override;
   std::list<std::string> getTableNames() override;
-  /**
-   * Get the constraint names but filters the result to be compatible with the database type passed in parameter
-   * @param tableName the table for which we want the constraint
-   * @param dbType the database type for which the results will be compatible
-   * @return  the constraint names filtered in order to be compatible with the database type passed in parameter
-   */
-  std::list<std::string> getConstraintNames(const std::string &tableName, cta::rdbms::Login::DbType dbType);
 };
 
 /**
@@ -103,4 +110,20 @@ public:
   static CatalogueMetadataGetter* create(const rdbms::Login::DbType dbType, cta::rdbms::Conn & conn);
 };
 
+/**
+ * This class is used to filter the Metadata that comes from the SQLite schema regarding the dbType we are currently checking
+ */
+class SchemaMetadataGetter: public MetadataGetter{
+protected:
+  std::unique_ptr<SQLiteCatalogueMetadataGetter> m_sqliteCatalogueMetadataGetter;
+  //The database type we would like to compare the SQLite schema against (used for filtering the results)
+  cta::rdbms::Login::DbType m_dbType;
+public:
+  SchemaMetadataGetter(std::unique_ptr<SQLiteCatalogueMetadataGetter> sqliteCatalogueMetadataGetter, const cta::rdbms::Login::DbType dbType);
+  virtual std::list<std::string> getIndexNames() override;
+  virtual std::list<std::string> getTableNames() override;
+  virtual std::map<std::string,std::string> getColumns(const std::string& tableName) override;
+  virtual std::list<std::string> getConstraintNames(const std::string& tableName) override;
+};
+
 }}
\ No newline at end of file
diff --git a/catalogue/SQLiteSchemaComparer.cpp b/catalogue/SQLiteSchemaComparer.cpp
index f7f9b1a578..c4c19a3488 100644
--- a/catalogue/SQLiteSchemaComparer.cpp
+++ b/catalogue/SQLiteSchemaComparer.cpp
@@ -28,9 +28,13 @@ namespace catalogue {
 SQLiteSchemaComparer::SQLiteSchemaComparer(const cta::rdbms::Login::DbType &catalogueDbType, rdbms::Conn &catalogueConn): SchemaComparer(catalogueDbType,catalogueConn) {
   log::DummyLogger dl("dummy","dummy");
   auto login = rdbms::Login::parseString("in_memory");
+  //Create SQLite connection
   m_sqliteConnPool.reset(new rdbms::ConnPool(login,1));
   m_sqliteConn = std::move(m_sqliteConnPool->getConn());
-  m_sqliteSchemaMetadataGetter.reset(new SQLiteCatalogueMetadataGetter(m_sqliteConn));
+  //Create the Metadata getter
+  std::unique_ptr<SQLiteCatalogueMetadataGetter> sqliteCatalogueMetadataGetter(new SQLiteCatalogueMetadataGetter(m_sqliteConn));
+  //Create the Schema Metadata Getter that will filter the SQLite schema metadata according to the catalogue database type we would like to compare
+  m_schemaMetadataGetter.reset(new SchemaMetadataGetter(std::move(sqliteCatalogueMetadataGetter),catalogueDbType));
 }
 
 SQLiteSchemaComparer::~SQLiteSchemaComparer() {
@@ -50,7 +54,7 @@ SchemaComparerResult SQLiteSchemaComparer::compareAll(){
 SchemaComparerResult SQLiteSchemaComparer::compareTables(){
   insertSchemaInSQLite();
   std::list<std::string> catalogueTables = m_catalogueMetadataGetter->getTableNames();
-  std::list<std::string> schemaTables = m_sqliteSchemaMetadataGetter->getTableNames();
+  std::list<std::string> schemaTables = m_schemaMetadataGetter->getTableNames();
   SchemaComparerResult res = compareTables(catalogueTables,schemaTables);
   return res;
 }
@@ -70,7 +74,7 @@ void SQLiteSchemaComparer::insertSchemaInSQLite() {
 SchemaComparerResult SQLiteSchemaComparer::compareIndexes(){
   insertSchemaInSQLite();
   std::list<std::string> catalogueIndexes = m_catalogueMetadataGetter->getIndexNames();
-  std::list<std::string> schemaIndexes = m_sqliteSchemaMetadataGetter->getIndexNames();
+  std::list<std::string> schemaIndexes = m_schemaMetadataGetter->getIndexNames();
   return compareItems("INDEX", catalogueIndexes, schemaIndexes);
 }
 
@@ -102,9 +106,9 @@ SchemaComparerResult SQLiteSchemaComparer::compareTables(const std::list<std::st
   }
   
   for(auto &schemaTable: schemaTables){
-    schemaTableColumns[schemaTable] = m_sqliteSchemaMetadataGetter->getColumns(schemaTable);
+    schemaTableColumns[schemaTable] = m_schemaMetadataGetter->getColumns(schemaTable);
     if(m_compareTableConstraints) {
-      schemaTableConstraints[schemaTable] = m_sqliteSchemaMetadataGetter->getConstraintNames(schemaTable,m_dbType);
+      schemaTableConstraints[schemaTable] = m_schemaMetadataGetter->getConstraintNames(schemaTable);
       result += compareItems("IN TABLE "+schemaTable+", CONSTRAINT",catalogueTableConstraints[schemaTable],schemaTableConstraints[schemaTable]);
     }
   }
diff --git a/catalogue/SQLiteSchemaComparer.hpp b/catalogue/SQLiteSchemaComparer.hpp
index 06a325dd31..f08d381c29 100644
--- a/catalogue/SQLiteSchemaComparer.hpp
+++ b/catalogue/SQLiteSchemaComparer.hpp
@@ -51,7 +51,7 @@ private:
   SchemaComparerResult compareTableColumns(const TableColumns & schema1TableColumns, const std::string &schema1Type,const TableColumns & schema2TableColumns, const std::string &schema2Type);
   rdbms::Conn m_sqliteConn;
   std::unique_ptr<rdbms::ConnPool> m_sqliteConnPool;
-  std::unique_ptr<SQLiteCatalogueMetadataGetter> m_sqliteSchemaMetadataGetter;
+  std::unique_ptr<SchemaMetadataGetter> m_schemaMetadataGetter;
   bool m_isSchemaInserted = false;
 };
 
diff --git a/catalogue/common_catalogue_schema.sql b/catalogue/common_catalogue_schema.sql
index 5e52a161a7..e53299c994 100644
--- a/catalogue/common_catalogue_schema.sql
+++ b/catalogue/common_catalogue_schema.sql
@@ -3,8 +3,7 @@ CREATE TABLE CTA_CATALOGUE(
   SCHEMA_VERSION_MINOR    UINT64TYPE      CONSTRAINT CTA_CATALOGUE_SVM2_NN NOT NULL,
   NEXT_SCHEMA_VERSION_MAJOR UINT64TYPE,
   NEXT_SCHEMA_VERSION_MINOR UINT64TYPE,
-  STATUS                  VARCHAR(100),
-  CONSTRAINT CATALOGUE_STATUS_CONTENT_CK CHECK((NEXT_SCHEMA_VERSION_MAJOR IS NULL AND NEXT_SCHEMA_VERSION_MINOR IS NULL AND STATUS='COMPLETE') OR (STATUS='UPGRADING'))
+  STATUS                  VARCHAR(100)
 );
 CREATE TABLE ADMIN_USER(
   ADMIN_USER_NAME         VARCHAR(100)    CONSTRAINT ADMIN_USER_AUN_NN  NOT NULL,
diff --git a/catalogue/migrations/liquibase/oracle/1.0to1.1.sql b/catalogue/migrations/liquibase/oracle/1.0to1.1.sql
index 8bca6adc7c..a6bd689d71 100644
--- a/catalogue/migrations/liquibase/oracle/1.0to1.1.sql
+++ b/catalogue/migrations/liquibase/oracle/1.0to1.1.sql
@@ -17,7 +17,7 @@ ADD (
 --changeset ccaffy:2 failOnError:true dbms:oracle
 --preconditions onFail:HALT onError:HALT
 --precondition-sql-check expectedResult:"1.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 CTA_CATALOGUE ADD CONSTRAINT CATALOGUE_STATUS_CONTENT_CK CHECK((NEXT_SCHEMA_VERSION_MAJOR IS NULL AND NEXT_SCHEMA_VERSION_MINOR IS NULL AND STATUS='COMPLETE') OR (STATUS='UPGRADING'));
+ALTER TABLE CTA_CATALOGUE ADD CONSTRAINT CATALOGUE_STATUS_CONTENT_CK CHECK((NEXT_SCHEMA_VERSION_MAJOR IS NULL AND NEXT_SCHEMA_VERSION_MINOR IS NULL AND STATUS='COMPLETE') OR (NEXT_SCHEMA_VERSION_MAJOR IS NOT NULL AND NEXT_SCHEMA_VERSION_MINOR IS NOT NULL AND STATUS='UPGRADING')) INITIALLY DEFERRED;
 --rollback ALTER TABLE CTA_CATALOGUE DROP CONSTRAINT CATALOGUE_STATUS_CONTENT_CK;
 
 --changeset ccaffy:3 failOnError:true dbms:oracle
diff --git a/catalogue/oracle_catalogue_schema_trailer.sql b/catalogue/oracle_catalogue_schema_trailer.sql
index 87ef767444..1ae83ac443 100644
--- a/catalogue/oracle_catalogue_schema_trailer.sql
+++ b/catalogue/oracle_catalogue_schema_trailer.sql
@@ -1 +1,3 @@
+ALTER TABLE CTA_CATALOGUE ADD CONSTRAINT CATALOGUE_STATUS_CONTENT_CK CHECK((NEXT_SCHEMA_VERSION_MAJOR IS NULL AND NEXT_SCHEMA_VERSION_MINOR IS NULL AND STATUS='COMPLETE') OR (NEXT_SCHEMA_VERSION_MAJOR IS NOT NULL AND NEXT_SCHEMA_VERSION_MINOR IS NOT NULL AND STATUS='UPGRADING')) INITIALLY DEFERRED;
+
 COMMIT;
-- 
GitLab