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

Implement getSchemaVersion for CatalogueSchema.

parent 353c889f
Branches
Tags
No related merge requests found
......@@ -21,6 +21,9 @@
#include "common/utils/utils.hpp"
#include "common/exception/Exception.hpp"
// TODO
#include <iostream>
namespace cta {
namespace catalogue {
......@@ -148,5 +151,34 @@ std::list<std::string> CatalogueSchema::getSchemaTriggerNames() const {
return schemaTriggers;
}
//------------------------------------------------------------------------------
// getSchemaVersion
//------------------------------------------------------------------------------
std::map<std::string, uint64_t> CatalogueSchema::getSchemaVersion() const {
try {
std::map<std::string, uint64_t> schemaVersion;
cta::utils::Regex schemaVersionRegex(
"INSERT INTO CTA_CATALOGUE\\("
" SCHEMA_VERSION_MAJOR,"
" SCHEMA_VERSION_MINOR\\)"
"VALUES\\("
" ([[:digit:]]+),"
" ([[:digit:]]+)\\);"
);
auto version = schemaVersionRegex.exec(sql);
if (3 == version.size()) {
schemaVersion.insert(std::make_pair("SCHEMA_VERSION_MAJOR", cta::utils::toUint64(version[1].c_str())));
schemaVersion.insert(std::make_pair("SCHEMA_VERSION_MINOR", cta::utils::toUint64(version[2].c_str())));
} else {
exception::Exception ex;
ex.getMessage() << "Could not find SCHEMA_VERSION";
throw ex;
}
return schemaVersion;
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
}
}
} // namespace catalogue
} // namespace cta
......@@ -20,6 +20,7 @@
#include <string>
#include <list>
#include <map>
namespace cta {
namespace catalogue {
......@@ -90,6 +91,12 @@ struct CatalogueSchema {
* @return The names of all the triggers in the catalogue schema.
*/
std::list<std::string> getSchemaTriggerNames() const;
/**
* TODO
* @return
*/
std::map<std::string, uint64_t> getSchemaVersion() const;
};
} // namespace catalogue
......
......@@ -28,6 +28,7 @@
#include "rdbms/AutocommitMode.hpp"
#include <algorithm>
#include <map>
namespace cta {
namespace catalogue {
......@@ -98,6 +99,12 @@ int VerifySchemaCmd::exceptionThrowingMain(const int argc, char *const *const ar
ex.getMessage() << "The catalogue schema uninitialized";
throw ex;
}
const auto schemaVersion = schema->getSchemaVersion();
for (const auto &schemaInfo : schemaVersion) {
std::cerr << schemaInfo.first << ':' << schemaInfo.second << std::endl;
}
std::cerr << "Checking table names..." << std::endl;
const auto schemaTableNames = schema->getSchemaTableNames();
const auto dbTableNames = conn.getTableNames();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment