lintel 0.2.0
Loading...
Searching...
No Matches
DatabaseBootstrapPlugin.h
Go to the documentation of this file.
1#ifndef LINTEL_DATABASEBOOTSTRAPPLUGIN_H
2#define LINTEL_DATABASEBOOTSTRAPPLUGIN_H
3
4#include <cstdint>
5#include <filesystem>
6#include <optional>
7
8#include "lintel/config.h"
12
13namespace lintel {
45{
46private:
47 struct FileInformation
48 {
49 std::string m_schemaName;
50 int32_t m_version;
51 std::filesystem::path m_filePath;
52 bool m_isInitFile;
53 };
54 std::filesystem::path m_configPath = std::filesystem::path(CONFIG_DIRECTORY) / "database";
55 std::shared_ptr<DatabaseConnectionConfigurations> m_connectionConfigurations;
56
57 static constexpr std::string_view m_createSchemaVersion =
58 R"(CREATE TABLE schema_version (name TEXT NOT NULL PRIMARY KEY,version BIGINT NOT NULL);)";
59
60 static std::optional<db::Result> hasSchemaVersionTable(
61 const std::shared_ptr<DatabaseConnectionEntry> &connectionEntry);
62
63 static void createSchemaVersionTable(const std::shared_ptr<DatabaseConnectionEntry> &connectionEntry);
64
65 static void initDatabase(const std::shared_ptr<DatabaseConnectionEntry> &connectionEntry,
66 const std::map<std::string, std::vector<FileInformation>> &initFiles,
67 const std::map<std::string, int32_t> &schemaVersions);
68
69 static void updateSchemaVersion(const db::Connection &connection,
70 const std::shared_ptr<DatabaseConnectionEntry> &connectionEntry,
71 const std::string &schemaName,
72 int32_t schemaVersion,
73 bool insert = true);
74
75 static void executeInitFile(db::Connection &connection,
76 const FileInformation &item,
77 const std::shared_ptr<DatabaseConnectionEntry> &connectionEntry,
78 int32_t &currentSchemaVersion);
79
80 static std::string schemaNameOf(const std::string &fileName);
81
82 static int32_t versionOf(const std::string &fileName);
83
93 static void registerReadinessCheck(const std::shared_ptr<DatabaseConnectionEntry> &connectionEntry);
94
102 static void registerConnectionPool(const std::shared_ptr<DatabaseConnectionEntry> &connectionEntry);
103
104 void handle(const std::shared_ptr<DatabaseConnectionEntry> &connectionEntry);
105
106public:
109 explicit DatabaseBootstrapPlugin(std::shared_ptr<DatabaseConnectionConfigurations> connectionConfigurations);
110
112 void onStart() override;
113
116};
117
118}// namespace lintel
119#endif// LINTEL_DATABASEBOOTSTRAPPLUGIN_H
Definition BootstrapPlugin.h:9
Definition BootstrapSequence.h:13
Definition DatabaseBootstrapPlugin.h:45
DatabaseBootstrapPlugin(std::shared_ptr< DatabaseConnectionConfigurations > connectionConfigurations)
BootstrapSequence getPriority() override
Definition Connection.h:25
Definition BaseFeature.h:6