/* * @project The CERN Tape Archive (CTA) * @copyright Copyright © 2021-2022 CERN * @license This program is free software, distributed under the terms of the GNU General Public * Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". You can * redistribute it and/or modify it under the terms of the GPL Version 3, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE. See the GNU General Public License for more details. * * In applying this licence, CERN does not waive the privileges and immunities * granted to it by virtue of its status as an Intergovernmental Organization or * submit itself to any jurisdiction. */ #pragma once #include #include "SchemaComparer.hpp" namespace cta::catalogue { /** * This class allows to compare a catalogue schema against a InMemory SQLite catalogue schema */ class SQLiteSchemaComparer: public SchemaComparer { public: /** * Constructs a SQLiteSchemaComparer * @param databaseToCheckName the database name to compare. * @param catalogueMetadataGetter the catalogue metadata getter to compare the catalogue schema content with the SQLite * database one */ SQLiteSchemaComparer(const std::string& databaseToCheckName, DatabaseMetadataGetter &catalogueMetadataGetter); /** * Compare the catalogue schema against the InMemory SQLite catalogue schema * @return a SchemaComparerResult object that will contain the differences if there are some */ SchemaCheckerResult compareAll() override; SchemaCheckerResult compareIndexes() override; SchemaCheckerResult compareTables() override; SchemaCheckerResult compareTablesLocatedInSchema() override; virtual ~SQLiteSchemaComparer(); private: void insertSchemaInSQLite(); enum Level {Warn, Error}; using Items = std::list; using LoggedItems = std::tuple; SchemaCheckerResult compareItems(const std::string &itemType, const LoggedItems& fromDatabase, const LoggedItems& fromSQLite); SchemaCheckerResult compareTables(const std::list &databaseTables, const std::list &schemaTables); typedef std::map> TableColumns; SchemaCheckerResult compareTableColumns(const TableColumns & schema1TableColumns, const std::string &schema1Type,const TableColumns & schema2TableColumns, const std::string &schema2Type); rdbms::Conn m_sqliteConn; std::unique_ptr m_sqliteConnPool; std::unique_ptr m_schemaMetadataGetter; bool m_isSchemaInserted = false; }; } // namespace cta::catalogue