Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
MigrationInspectorFactory.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2025, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include "data/BackendInterface.hpp"
23#include "migration/MigrationInspectorInterface.hpp"
24#include "migration/MigratiorStatus.hpp"
25#include "migration/cassandra/CassandraMigrationManager.hpp"
26#include "util/Assert.hpp"
27#include "util/log/Logger.hpp"
28#include "util/newconfig/ConfigDefinition.hpp"
29
30#include <boost/algorithm/string.hpp>
31#include <boost/algorithm/string/predicate.hpp>
32
33#include <memory>
34#include <utility>
35
36namespace migration {
37
45inline std::shared_ptr<MigrationInspectorInterface>
46makeMigrationInspector(
48 std::shared_ptr<BackendInterface> const& backend
49)
50{
51 ASSERT(backend != nullptr, "Backend is not initialized");
52
53 auto inspector = std::make_shared<migration::cassandra::CassandraMigrationInspector>(backend);
54
55 // Database is empty, we need to initialize the migration table if it is a writeable backend
56 if (not config.get<bool>("read_only") and not backend->hardFetchLedgerRangeNoThrow()) {
57 migration::MigratorStatus const migrated(migration::MigratorStatus::Migrated);
58 for (auto const& name : inspector->allMigratorsNames()) {
59 backend->writeMigratorStatus(name, migrated.toString());
60 }
61 }
62 return inspector;
63}
64
65} // namespace migration
The status of a migrator, it provides the helper functions to convert the status to string and vice v...
Definition MigratiorStatus.hpp:31
All the config data will be stored and extracted from this class.
Definition ConfigDefinition.hpp:54
T get(std::string_view fullKey) const
Returns the specified value of given string if value exists.
Definition ConfigDefinition.hpp:108