diff --git a/catalogue/CatalogueSchema.cpp b/catalogue/CatalogueSchema.cpp index f954f77485ba32192817fbc1893055feabc9017b..86a3dbed2ab036b0d76f145b418af25a59deb4df 100644 --- a/catalogue/CatalogueSchema.cpp +++ b/catalogue/CatalogueSchema.cpp @@ -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 { diff --git a/catalogue/CatalogueSchema.hpp b/catalogue/CatalogueSchema.hpp index 0f09e7b2559f529f3c0e417714f63282afb9e46f..952762eea429c94814e0bf9cbbc310ba6ba8a942 100644 --- a/catalogue/CatalogueSchema.hpp +++ b/catalogue/CatalogueSchema.hpp @@ -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; }; diff --git a/catalogue/SqliteCatalogueSchema.hpp b/catalogue/SqliteCatalogueSchema.hpp index ae03711012f6ba6f1b9a509a094c76397c0320b6..fd0b80befb3e05522cc28c385952e538232f7dbe 100644 --- a/catalogue/SqliteCatalogueSchema.hpp +++ b/catalogue/SqliteCatalogueSchema.hpp @@ -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 { diff --git a/catalogue/VerifySchemaCmd.cpp b/catalogue/VerifySchemaCmd.cpp index 2c578df926863f9fec0e6ee4e1cc8770f4af18e1..f86f7bec7f385850852c77ce8af2c716232c2016 100644 --- a/catalogue/VerifySchemaCmd.cpp +++ b/catalogue/VerifySchemaCmd.cpp @@ -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; diff --git a/catalogue/VerifySchemaCmd.hpp b/catalogue/VerifySchemaCmd.hpp index fdd1414392fc24c64a24729b9141b02d480c0dfa..0c176195bc1c8eaa58894c616d05242e6e0164eb 100644 --- a/catalogue/VerifySchemaCmd.hpp +++ b/catalogue/VerifySchemaCmd.hpp @@ -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;