Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
CassandraMigrationSchema.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2024, 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/cassandra/Handle.hpp"
23#include "data/cassandra/Schema.hpp"
24#include "data/cassandra/SettingsProvider.hpp"
25#include "data/cassandra/Types.hpp"
26
27#include <fmt/core.h>
28
29#include <functional>
30#include <string>
31
32namespace migration::cassandra::impl {
33
39 std::reference_wrapper<SettingsProviderType const> settingsProvider_;
40
41public:
47 explicit CassandraMigrationSchema(SettingsProviderType const& settings) : settingsProvider_{settings}
48 {
49 }
50
61 data::cassandra::Handle const& handler,
62 std::string const& tableName,
63 std::string const& key
64 )
65 {
66 return handler.prepare(fmt::format(
67 R"(
68 SELECT *
69 FROM {}
70 WHERE TOKEN({}) >= ? AND TOKEN({}) <= ?
71 )",
72 data::cassandra::qualifiedTableName<SettingsProviderType>(settingsProvider_.get(), tableName),
73 key,
74 key
75 ));
76 }
77
86 {
87 static auto kPREPARED = handler.prepare(fmt::format(
88 R"(
89 INSERT INTO {}
90 (migrator_name, status)
91 VALUES (?, ?)
92 )",
93 data::cassandra::qualifiedTableName<SettingsProviderType>(settingsProvider_.get(), "migrator_status")
94 ));
95 return kPREPARED;
96 }
97};
98} // namespace migration::cassandra::impl
Represents a handle to the cassandra database cluster.
Definition Handle.hpp:46
PreparedStatementType prepare(std::string_view query) const
Prepare a statement.
Definition Handle.cpp:156
Provides settings for BasicCassandraBackend.
Definition SettingsProvider.hpp:35
Represents a prepared statement on the DB side.
Definition Statement.hpp:155
The schema for the migration process. It contains the prepared statements only used for the migration...
Definition CassandraMigrationSchema.hpp:37
data::cassandra::PreparedStatement getPreparedFullScanStatement(data::cassandra::Handle const &handler, std::string const &tableName, std::string const &key)
Get the prepared statement for the full scan of a table.
Definition CassandraMigrationSchema.hpp:60
data::cassandra::PreparedStatement const & getPreparedInsertMigratedMigrator(data::cassandra::Handle const &handler)
Get the prepared statement for insertion of migrator_status table.
Definition CassandraMigrationSchema.hpp:81
CassandraMigrationSchema(SettingsProviderType const &settings)
Construct a new Cassandra Migration Schema object.
Definition CassandraMigrationSchema.hpp:47
std::string qualifiedTableName(SettingsProviderType const &provider, std::string_view name)
Returns the table name qualified with the keyspace and table prefix.
Definition Schema.hpp:46