Commit b73e1bef authored by Steven Murray's avatar Steven Murray
Browse files

Removed triggers from the CTA catalogue schema because we now use version 10.3...

Removed triggers from the CTA catalogue schema because we now use version 10.3 of the MariaDB database server which unlike version 5.5 enforces check constraints
parent 5eafc49c
......@@ -152,14 +152,9 @@ add_custom_command(OUTPUT mysql_catalogue_schema.cpp
COMMAND sed 's/^/\ \ \"/' mysql_catalogue_schema.sql | sed 's/$$/\"/' > mysql_catalogue_schema.cpp
DEPENDS mysql_catalogue_schema.sql)
add_custom_command(OUTPUT mysql_catalogue_schema_trigger.cpp
COMMAND sed 's/^/\ \ \"/' ${CMAKE_CURRENT_SOURCE_DIR}/mysql_catalogue_schema_trigger.sql | sed 's/$$/\"/' > mysql_catalogue_schema_trigger.cpp
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/mysql_catalogue_schema_trigger.sql)
add_custom_command(OUTPUT MysqlCatalogueSchema.cpp
COMMAND sed -e '/CTA_SQL_SCHEMA/r mysql_catalogue_schema.cpp' -e '/CTA_SQL_TRIGGER/r mysql_catalogue_schema_trigger.cpp' ${CMAKE_CURRENT_SOURCE_DIR}/MysqlCatalogueSchema.before_SQL.cpp > MysqlCatalogueSchema.cpp
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/MysqlCatalogueSchema.before_SQL.cpp mysql_catalogue_schema.cpp mysql_catalogue_schema_trigger.cpp)
COMMAND sed -e '/CTA_SQL_SCHEMA/r mysql_catalogue_schema.cpp' ${CMAKE_CURRENT_SOURCE_DIR}/MysqlCatalogueSchema.before_SQL.cpp > MysqlCatalogueSchema.cpp
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/MysqlCatalogueSchema.before_SQL.cpp mysql_catalogue_schema.cpp)
# For Postgres
add_custom_command(OUTPUT postgres_catalogue_schema.cpp
......
......@@ -29,12 +29,6 @@ namespace catalogue {
//------------------------------------------------------------------------------
CatalogueSchema::CatalogueSchema(const std::string &sqlSchema): sql(sqlSchema) {
}
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
CatalogueSchema::CatalogueSchema(const std::string &sqlSchema,
const std::string &sqlSchemaTrigger): sql(sqlSchema), sql_trigger(sqlSchemaTrigger) {
}
//------------------------------------------------------------------------------
// getSchemaColumns
......@@ -176,34 +170,6 @@ std::list<std::string> CatalogueSchema::getSchemaSequenceNames() const {
return schemaSequences;
}
//------------------------------------------------------------------------------
// getSchemaTriggerNames
//------------------------------------------------------------------------------
std::list<std::string> CatalogueSchema::getSchemaTriggerNames() const {
std::list<std::string> schemaTriggers;
std::string::size_type searchPos = 0;
std::string::size_type findResult = std::string::npos;
try {
while(std::string::npos != (findResult = sql_trigger.find(';', searchPos))) {
// Calculate the length of the current statement without the trailing ';'
const std::string::size_type stmtLen = findResult - searchPos;
const std::string sqlStmt = utils::trimString(sql_trigger.substr(searchPos, stmtLen));
searchPos = findResult + 1;
if(0 < sqlStmt.size()) { // Ignore empty statements
cta::utils::Regex tableTriggersRegex("CREATE TRIGGER `([a-zA-Z_]+)`");
auto triggerName = tableTriggersRegex.exec(sqlStmt);
if (2 == triggerName.size()) {
schemaTriggers.push_back(triggerName[1].c_str());
}
}
}
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
}
return schemaTriggers;
}
//------------------------------------------------------------------------------
// getSchemaVersion
//------------------------------------------------------------------------------
......
......@@ -38,26 +38,11 @@ struct CatalogueSchema {
*/
CatalogueSchema(const std::string &sqlSchema);
/**
* Constructor.
*
* @param sqlSchema The sql for the catalogue schema provided at compilation
* time.
* @param sqlTriggerSchema The sql for triggers in the catalogue schema provided
* at compilation time only for schemas that support triggers.
*/
CatalogueSchema(const std::string &sqlSchema, const std::string &sqlTriggerSchema);
/**
* The schema.
*/
const std::string sql;
/**
* The trigger.
*/
const std::string sql_trigger;
/**
* Returns the names of all the tables in the catalogue schema.
*
......@@ -91,16 +76,6 @@ struct CatalogueSchema {
*/
std::list<std::string> getSchemaSequenceNames() const;
/**
* Returns the names of all the triggers in the catalogue schema.
*
* if the underlying database technologies does not supported triggers then
* this method simply returns an empty list.*
*
* @return The names of all the triggers in the catalogue schema.
*/
std::list<std::string> getSchemaTriggerNames() const;
/**
* Returns the map of strings to uint64 for the catalogue SCHEMA_VERSION_MAJOR
* and SCHEMA_VERSION_MINOR values.
......
......@@ -85,12 +85,6 @@ int CreateSchemaCmd::exceptionThrowingMain(const int argc, char *const *const ar
{
MysqlCatalogueSchema schema;
executeNonQueries(conn, schema.sql);
// execute triggers
auto triggers = schema.triggers();
for (auto trigger: triggers) {
conn.executeNonQuery(trigger);
}
}
break;
case rdbms::Login::DBTYPE_ORACLE:
......
......@@ -26,37 +26,8 @@ namespace catalogue {
//------------------------------------------------------------------------------
MysqlCatalogueSchema::MysqlCatalogueSchema(): CatalogueSchema(
// CTA_SQL_SCHEMA - The contents of sqlite_catalogue_schema.cpp go here
,
// CTA_SQL_TRIGGER - The contents of mysql_catalogue_schema_trigger.cpp go here
) {
}
std::vector<std::string>
MysqlCatalogueSchema::triggers() {
std::vector<std::string> results;
// assume each trigger command starts with "CREATE TRIGGER"
const std::string trigger_prefix = "CREATE TRIGGER";
const std::string& sql_str = sql_trigger;
size_t idx = sql_str.find(trigger_prefix);
while (idx != std::string::npos) {
size_t idx_next = sql_str.find(trigger_prefix, idx+1);
size_t len = 0;
if (idx_next != std::string::npos) {
len = idx_next - idx;
} else {
len = idx_next;
}
std::string s = sql_str.substr(idx, len);
results.push_back(s);
idx = idx_next;
}
return results;
}
} // namespace catalogue
} // namespace cta
......@@ -129,16 +129,10 @@ int VerifySchemaCmd::exceptionThrowingMain(const int argc, char *const *const ar
const auto dbSequenceNames = conn.getSequenceNames();
const VerifyStatus verifySequencesStatus = verifySequenceNames(schemaSequenceNames, dbSequenceNames);
std::cerr << "Checking trigger names..." << std::endl;
const auto schemaTriggerNames = schema->getSchemaTriggerNames();
const auto dbTriggerNames = conn.getTriggerNames();
const VerifyStatus verifyTriggersStatus = verifyTriggerNames(schemaTriggerNames, dbTriggerNames);
if (verifySchemaStatus == VerifyStatus::ERROR ||
verifyTablesStatus == VerifyStatus::ERROR ||
verifyIndexesStatus == VerifyStatus::ERROR ||
verifySequencesStatus == VerifyStatus::ERROR ||
verifyTriggersStatus == VerifyStatus::ERROR ||
verifyColumnsStatus == VerifyStatus::ERROR ) {
return 1;
}
......@@ -352,38 +346,5 @@ VerifySchemaCmd::VerifyStatus VerifySchemaCmd::verifySequenceNames(const std::li
}
}
//------------------------------------------------------------------------------
// verifyTriggerNames
//------------------------------------------------------------------------------
VerifySchemaCmd::VerifyStatus VerifySchemaCmd::verifyTriggerNames(const std::list<std::string> &schemaTriggerNames,
const std::list<std::string> &dbTriggerNames) const {
try {
VerifyStatus status = VerifyStatus::UNKNOWN;
for(auto &triggerName : schemaTriggerNames) {
const bool schemaTriggerIsNotInDb = dbTriggerNames.end() == std::find(dbTriggerNames.begin(), dbTriggerNames.end(), triggerName);
if (schemaTriggerIsNotInDb) {
std::cerr << " ERROR: the schema trigger " << triggerName << " not found in the DB" << std::endl;
status = VerifyStatus::ERROR;
}
}
for(auto &triggerName : dbTriggerNames) {
const bool dbTriggerIsNotInSchema = schemaTriggerNames.end() == std::find(schemaTriggerNames.begin(), schemaTriggerNames.end(), triggerName);
if (dbTriggerIsNotInSchema) {
std::cerr << " INFO: the database trigger " << triggerName << " not found in the schema" << std::endl;
if ( VerifyStatus::ERROR != status) {
status = VerifyStatus::INFO;
}
}
}
if (status != VerifyStatus::INFO && status != VerifyStatus::ERROR) {
std::cerr << " OK" << std::endl;
status = VerifyStatus::OK;
}
return status;
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
}
}
} // namespace catalogue
} // namespace cta
......@@ -137,16 +137,6 @@ private:
VerifyStatus verifySequenceNames(const std::list<std::string> &schemaSequenceNames,
const std::list<std::string> &dbSequenceNames) const;
/**
* Verifies trigger names in the database against the catalogue schema trigger names.
* Returns verification status as result.
*
* @param schemaTriggerNames The list of the catalogue schema trigger names.
* @param dbTrgigerNames The list of the database trigger names.
* @return The verification status code.
*/
VerifyStatus verifyTriggerNames(const std::list<std::string> &schemaTriggerNames,
const std::list<std::string> &dbTrgigerNames) const;
}; // class VerifySchemaCmd
} // namespace catalogue
......
CREATE TRIGGER `TAPE_POOL_IS_ENCRYPTED_BOOL_CK_BEFORE_INSERT` BEFORE INSERT ON `TAPE_POOL`
FOR EACH ROW
BEGIN
IF new.IS_ENCRYPTED NOT IN ('0','1') THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'TAPE_POOL.IS_ENCRYPTED should be 0 or 1';
END IF;
END;
CREATE TRIGGER `TAPE_POOL_IS_ENCRYPTED_BOOL_CK_BEFORE_UPDATE` BEFORE UPDATE ON `TAPE_POOL`
FOR EACH ROW
BEGIN
IF new.IS_ENCRYPTED NOT IN ('0','1') THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'TAPE_POOL.IS_ENCRYPTED should be 0 or 1';
END IF;
END;
CREATE TRIGGER `ARCHIVE_ROUTE_COPY_NB_GT_ZERO_BEFORE_INSERT` BEFORE INSERT ON `ARCHIVE_ROUTE`
FOR EACH ROW
BEGIN
IF new.COPY_NB <= 0 THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'ARCHIVE_ROUTE.COPY_NB should be greater than 0';
END IF;
END;
CREATE TRIGGER `ARCHIVE_ROUTE_COPY_NB_GT_ZERO_BEFORE_UPDATE` BEFORE UPDATE ON `ARCHIVE_ROUTE`
FOR EACH ROW
BEGIN
IF new.COPY_NB <= 0 THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'ARCHIVE_ROUTE.COPY_NB should be greater than 0';
END IF;
END;
CREATE TRIGGER `CHECK_TAPE_BEFORE_INSERT` BEFORE INSERT ON `TAPE`
FOR EACH ROW
BEGIN
IF new.IS_DISABLED not in ('0','1') THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'TAPE.IS_DISABLED should be 0 or 1';
END IF;
IF new.IS_FULL not in ('0','1') THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'TAPE.IS_FULL should be 0 or 1';
END IF;
IF new.IS_READ_ONLY not in ('0','1') THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'TAPE.IS_READ_ONLY should be 0 or 1';
END IF;
IF new.IS_FROM_CASTOR not in ('0','1') THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'TAPE.IS_FROM_CASTOR should be 0 or 1';
END IF;
END;
CREATE TRIGGER `CHECK_TAPE_BEFORE_UPDATE` BEFORE UPDATE ON `TAPE`
FOR EACH ROW
BEGIN
IF new.IS_DISABLED not in ('0','1') THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'TAPE.IS_DISABLED should be 0 or 1';
END IF;
IF new.IS_FULL not in ('0','1') THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'TAPE.IS_FULL should be 0 or 1';
END IF;
IF new.IS_READ_ONLY not in ('0','1') THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'TAPE.IS_READ_ONLY should be 0 or 1';
END IF;
IF new.IS_FROM_CASTOR not in ('0','1') THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'TAPE.IS_FROM_CASTOR should be 0 or 1';
END IF;
IF new.IS_ARCHIVED not in ('0','1') THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'TAPE.IS_ARCHIVED should be 0 or 1';
END IF;
IF new.IS_EXPORTED not in ('0','1') THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'TAPE.IS_EXPORTED should be 0 or 1';
END IF;
END;
CREATE TRIGGER `TAPE_FILE_COPY_NB_GT_ZERO_BEFORE_INSERT` BEFORE INSERT ON `TAPE_FILE`
FOR EACH ROW
BEGIN
IF new.COPY_NB <= 0 THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'TAPE_FILE.COPY_NB should be greater than 0';
END IF;
END;
CREATE TRIGGER `TAPE_FILE_COPY_NB_GT_ZERO_BEFORE_UPDATE` BEFORE UPDATE ON `TAPE_FILE`
FOR EACH ROW
BEGIN
IF new.COPY_NB <= 0 THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'TAPE_FILE.COPY_NB should be greater than 0';
END IF;
END;
CREATE TRIGGER `CHECK_LOGICAL_LIBRARY_BEFORE_INSERT` BEFORE INSERT ON `LOGICAL_LIBRARY`
FOR EACH ROW
BEGIN
IF new.IS_DISABLED not in ('0','1') THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'LOGICAL_LIBRARY.IS_DISABLED should be 0 or 1';
END IF;
END;
CREATE TRIGGER `CHECK_LOGICAL_LIBRARY_BEFORE_UPDATE` BEFORE UPDATE ON `LOGICAL_LIBRARY`
FOR EACH ROW
BEGIN
IF new.IS_DISABLED not in ('0','1') THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'LOGICAL_LIBRARY.IS_DISABLED should be 0 or 1';
END IF;
END;
CREATE TRIGGER `CHECK_ARCHIVE_FILE_BEFORE_INSERT` BEFORE INSERT ON `ARCHIVE_FILE`
FOR EACH ROW
BEGIN
IF new.IS_DELETED not in ('0','1') THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'ARCHIVE_FILE.IS_DELETED should be 0 or 1';
END IF;
END;
CREATE TRIGGER `CHECK_ARCHIVE_FILE_BEFORE_UPDATE` BEFORE UPDATE ON `ARCHIVE_FILE`
FOR EACH ROW
BEGIN
IF new.IS_DELETED not in ('0','1') THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'ARCHIVE_FILE.IS_DELETED should be 0 or 1';
END IF;
END;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment