Skip to content
Snippets Groups Projects
Commit 3114f5ad authored by Victor Kotlyar's avatar Victor Kotlyar
Browse files

Make verification same for all database backends. Code cleanup.

parent 2d05bb55
Branches
Tags
No related merge requests found
......@@ -17,6 +17,9 @@
*/
#include "catalogue/CatalogueSchema.hpp"
#include "common/utils/Regex.hpp"
#include "common/utils/utils.hpp"
#include "common/exception/Exception.hpp"
namespace cta {
namespace catalogue {
......
......@@ -18,16 +18,9 @@
#pragma once
#include "common/utils/Regex.hpp"
#include "common/utils/utils.hpp"
#include "common/exception/Exception.hpp"
#include <string>
#include <list>
// TODO
#include <iostream>
namespace cta {
namespace catalogue {
......@@ -37,9 +30,21 @@ namespace catalogue {
*/
struct CatalogueSchema {
/**
* Constructors.
* Constructor.
*
* @param sqlSchema The sql for the catalogue schema provided at compilation
* time.
*/
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);
/**
......@@ -53,27 +58,36 @@ struct CatalogueSchema {
const std::string sql_trigger;
/**
* TODO
*
* @return
* Returns the names of all the tables in the catalogue schema.
*
* @return The names of all the tables in the catalogue schema.
*/
std::list<std::string> getSchemaTableNames() const;
/**
* TODO
*
* @return
* Returns the names of all the indexes in the catalogue schema.
*
* @return The names of all the indexes in the catalogue schema.
*/
std::list<std::string> getSchemaIndexNames() const;
/**
* TODO
* Returns the names of all the sequences in the catalogue schema.
*
* @return
* if the underlying database technologies does not supported sequences then
* this method simply returns an empty list.
*
* @return The names of all the sequences in the catalogue schema.
*/
std::list<std::string> getSchemaSequenceNames() const;
/**
* TODO
* 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
* @return The names of all the triggers in the catalogue schema.
*/
std::list<std::string> getSchemaTriggerNames() const;
};
......
......@@ -18,18 +18,8 @@
#pragma once
#include "common/utils/Regex.hpp"
#include "common/utils/utils.hpp"
#include "common/exception/Exception.hpp"
#include "CatalogueSchema.hpp"
#include <string>
#include <list>
// TODO
#include <iostream>
namespace cta {
namespace catalogue {
......
......@@ -67,110 +67,21 @@ int VerifySchemaCmd::exceptionThrowingMain(const int argc, char *const *const ar
std::cerr << "Cannot verify the database schema because the CTA_CATALOGUE table does not exists" << std::endl;
return 1;
}
std::unique_ptr<CatalogueSchema> schema;
switch(login.dbType) {
case rdbms::Login::DBTYPE_IN_MEMORY:
case rdbms::Login::DBTYPE_SQLITE:
{
// TODO
SqliteCatalogueSchema schema;
std::cerr << "Checking table names..." << std::endl;
const auto schemaTableNames = schema.getSchemaTableNames();
const auto dbTableNames = conn.getTableNames();
std::cerr << "error code: "<< static_cast<int>(verifyTableNames(schemaTableNames, dbTableNames)) << std::endl;
std::cerr << "Checking index names..." << std::endl;
const auto schemaIndexNames = schema.getSchemaIndexNames();
const auto dbIndexNames = conn.getIndexNames();
std::cerr << "error code: "<< static_cast<int>(verifyIndexNames(schemaIndexNames, dbIndexNames)) << std::endl;
std::cerr << "Checking sequence names..." << std::endl;
const auto schemaSequenceNames = schema.getSchemaSequenceNames();
const auto dbSequenceNames = conn.getSequenceNames();
std::cerr << "error code: "<< static_cast<int>(verifySequenceNames(schemaSequenceNames, dbSequenceNames)) << std::endl;
std::cerr << "Checking trigger names..." << std::endl;
const auto schemaTriggerNames = schema.getSchemaTriggerNames();
const auto dbTriggerNames = conn.getTriggerNames();
std::cerr << "error code: "<< static_cast<int>(verifyTriggerNames(schemaTriggerNames, dbTriggerNames)) << std::endl;
}
schema.reset(new SqliteCatalogueSchema);
break;
case rdbms::Login::DBTYPE_POSTGRESQL:
{
// TODO
PostgresCatalogueSchema schema;
std::cerr << "Checking table names..." << std::endl;
const auto schemaTableNames = schema.getSchemaTableNames();
const auto dbTableNames = conn.getTableNames();
std::cerr << "error code: "<< static_cast<int>(verifyTableNames(schemaTableNames, dbTableNames)) << std::endl;
std::cerr << "Checking index names..." << std::endl;
const auto schemaIndexNames = schema.getSchemaIndexNames();
const auto dbIndexNames = conn.getIndexNames();
std::cerr << "error code: "<< static_cast<int>(verifyIndexNames(schemaIndexNames, dbIndexNames)) << std::endl;
std::cerr << "Checking sequence names..." << std::endl;
const auto schemaSequenceNames = schema.getSchemaSequenceNames();
const auto dbSequenceNames = conn.getSequenceNames();
std::cerr << "error code: "<< static_cast<int>(verifySequenceNames(schemaSequenceNames, dbSequenceNames)) << std::endl;
std::cerr << "Checking trigger names..." << std::endl;
const auto schemaTriggerNames = schema.getSchemaTriggerNames();
const auto dbTriggerNames = conn.getTriggerNames();
std::cerr << "error code: "<< static_cast<int>(verifyTriggerNames(schemaTriggerNames, dbTriggerNames)) << std::endl;
}
schema.reset(new PostgresCatalogueSchema);
break;
case rdbms::Login::DBTYPE_MYSQL:
{
// TODO
MysqlCatalogueSchema schema;
std::cerr << "Checking table names..." << std::endl;
const auto schemaTableNames = schema.getSchemaTableNames();
const auto dbTableNames = conn.getTableNames();
std::cerr << "error code: "<< static_cast<int>(verifyTableNames(schemaTableNames, dbTableNames)) << std::endl;
std::cerr << "Checking index names..." << std::endl;
const auto schemaIndexNames = schema.getSchemaIndexNames();
const auto dbIndexNames = conn.getIndexNames();
std::cerr << "error code: "<< static_cast<int>(verifyIndexNames(schemaIndexNames, dbIndexNames)) << std::endl;
std::cerr << "Checking sequence names..." << std::endl;
const auto schemaSequenceNames = schema.getSchemaSequenceNames();
const auto dbSequenceNames = conn.getSequenceNames();
std::cerr << "error code: "<< static_cast<int>(verifySequenceNames(schemaSequenceNames, dbSequenceNames)) << std::endl;
// execute triggers
std::cerr << "Checking trigger names..." << std::endl;
const auto schemaTriggerNames = schema.getSchemaTriggerNames();
const auto dbTriggerNames = conn.getTriggerNames();
std::cerr << "error code: "<< static_cast<int>(verifyTriggerNames(schemaTriggerNames, dbTriggerNames)) << std::endl;
}
schema.reset(new MysqlCatalogueSchema);
break;
case rdbms::Login::DBTYPE_ORACLE:
{
// TODO
OracleCatalogueSchema schema;
std::cerr << "Checking table names..." << std::endl;
const auto schemaTableNames = schema.getSchemaTableNames();
const auto dbTableNames = conn.getTableNames();
std::cerr << "error code: "<< static_cast<int>(verifyTableNames(schemaTableNames, dbTableNames)) << std::endl;
std::cerr << "Checking index names..." << std::endl;
const auto schemaIndexNames = schema.getSchemaIndexNames();
const auto dbIndexNames = conn.getIndexNames();
std::cerr << "error code: "<< static_cast<int>(verifyIndexNames(schemaIndexNames, dbIndexNames)) << std::endl;
std::cerr << "Checking sequence names..." << std::endl;
const auto schemaSequenceNames = schema.getSchemaSequenceNames();
const auto dbSequenceNames = conn.getSequenceNames();
std::cerr << "error code: "<< static_cast<int>(verifySequenceNames(schemaSequenceNames, dbSequenceNames)) << std::endl;
// execute triggers
std::cerr << "Checking trigger names..." << std::endl;
const auto schemaTriggerNames = schema.getSchemaTriggerNames();
const auto dbTriggerNames = conn.getTriggerNames();
std::cerr << "error code: "<< static_cast<int>(verifyTriggerNames(schemaTriggerNames, dbTriggerNames)) << std::endl;
}
schema.reset(new OracleCatalogueSchema);
break;
case rdbms::Login::DBTYPE_NONE:
throw exception::Exception("Cannot verify a catalogue without a database type");
......@@ -182,6 +93,32 @@ int VerifySchemaCmd::exceptionThrowingMain(const int argc, char *const *const ar
}
}
std::cerr << "Checking table names..." << std::endl;
const auto schemaTableNames = schema->getSchemaTableNames();
const auto dbTableNames = conn.getTableNames();
const VerifyStatus verifyTablesStatus = verifyTableNames(schemaTableNames, dbTableNames);
std::cerr << "Checking index names..." << std::endl;
const auto schemaIndexNames = schema->getSchemaIndexNames();
const auto dbIndexNames = conn.getIndexNames();
const VerifyStatus verifyIndexesStatus = verifyIndexNames(schemaIndexNames, dbIndexNames);
std::cerr << "Checking sequence names..." << std::endl;
const auto schemaSequenceNames = schema->getSchemaSequenceNames();
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 (verifyTablesStatus == VerifyStatus::ERROR ||
verifyIndexesStatus == VerifyStatus::ERROR ||
verifySequencesStatus == VerifyStatus::ERROR ||
verifyTriggersStatus == VerifyStatus::ERROR ) {
return 1;
}
return 0;
}
......@@ -230,7 +167,7 @@ VerifySchemaCmd::VerifyStatus VerifySchemaCmd::verifyTableNames(const std::list<
}
}
if (status != VerifyStatus::INFO && status != VerifyStatus::ERROR) {
std::cerr << " OK: no problems found" << std::endl;
std::cerr << " OK" << std::endl;
status = VerifyStatus::OK;
}
return status;
......@@ -261,7 +198,7 @@ VerifySchemaCmd::VerifyStatus VerifySchemaCmd::verifyIndexNames(const std::list<
}
}
if (status != VerifyStatus::INFO && status != VerifyStatus::ERROR) {
std::cerr << " OK: no problems found" << std::endl;
std::cerr << " OK" << std::endl;
status = VerifyStatus::OK;
}
return status;
......@@ -292,7 +229,7 @@ VerifySchemaCmd::VerifyStatus VerifySchemaCmd::verifySequenceNames(const std::li
}
}
if (status != VerifyStatus::INFO && status != VerifyStatus::ERROR) {
std::cerr << " OK: no problems found" << std::endl;
std::cerr << " OK" << std::endl;
status = VerifyStatus::OK;
}
return status;
......@@ -323,7 +260,7 @@ VerifySchemaCmd::VerifyStatus VerifySchemaCmd::verifyTriggerNames(const std::lis
}
}
if (status != VerifyStatus::INFO && status != VerifyStatus::ERROR) {
std::cerr << " OK: no problems found" << std::endl;
std::cerr << " OK" << std::endl;
status = VerifyStatus::OK;
}
return status;
......
......@@ -75,37 +75,45 @@ private:
bool tableExists(const std::string tableName, rdbms::Conn &conn) const;
/**
* TODO
* @param
* @param
* @return
* Verifies table names in the database against the catalogue schema table names.
* Returns verification status as result.
*
* @param schemaTableNames The list of the catalogue schema table names.
* @param dbTableNames The list of the database table names.
* @return The verification status code.
*/
VerifyStatus verifyTableNames(const std::list<std::string> &schemaTableNames,
const std::list<std::string> &dbTableNames) const;
/**
* TODO
* @param
* @param
* @return
* Verifies index names in the database against the catalogue schema index names.
* Returns verification status as result.
*
* @param schemaIndexNames The list of the catalogue schema index names.
* @param dbIndexNames The list of the database index names.
* @return The verification status code.
*/
VerifyStatus verifyIndexNames(const std::list<std::string> &schemaIndexNames,
const std::list<std::string> &dbIndexNames) const;
/**
* TODO
* @param
* @param
* @return
* Verifies sequence names in the database against the catalogue schema sequence names.
* Returns verification status as result.
*
* @param schemaSequenceNames The list of the catalogue schema sequence names.
* @param dbSequenceNames The list of the database sequence names.
* @return The verification status code.
*/
VerifyStatus verifySequenceNames(const std::list<std::string> &schemaSequenceNames,
const std::list<std::string> &dbSequenceNames) const;
/**
* TODO
* @param
* @param
* @return
* 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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment