refactor db directory
This commit is contained in:
parent
f8ded1ecd1
commit
69d44c27cc
@ -37,7 +37,14 @@ create_rocksdb(const repertory::app_config &cfg, const std::string &name,
|
||||
-> std::unique_ptr<rocksdb::TransactionDB> {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
auto path = repertory::utils::path::combine(cfg.get_data_directory(), {name});
|
||||
auto db_dir =
|
||||
repertory::utils::path::combine(cfg.get_data_directory(), {"db"});
|
||||
if (not repertory::utils::file::directory{db_dir}.create_directory()) {
|
||||
throw startup_exception(
|
||||
fmt::format("failed to create db directory|", db_dir));
|
||||
}
|
||||
|
||||
auto path = repertory::utils::path::combine(db_dir, {name});
|
||||
if (clear &&
|
||||
not repertory::utils::file::directory{path}.remove_recursively()) {
|
||||
repertory::utils::error::raise_error(
|
||||
|
@ -37,7 +37,14 @@ create_rocksdb(const repertory::app_config &cfg, const std::string &name,
|
||||
-> std::unique_ptr<rocksdb::TransactionDB> {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
auto path = repertory::utils::path::combine(cfg.get_data_directory(), {name});
|
||||
auto db_dir =
|
||||
repertory::utils::path::combine(cfg.get_data_directory(), {"db"});
|
||||
if (not repertory::utils::file::directory{db_dir}.create_directory()) {
|
||||
throw startup_exception(
|
||||
fmt::format("failed to create db directory|", db_dir));
|
||||
}
|
||||
|
||||
auto path = repertory::utils::path::combine(db_dir, {name});
|
||||
if (clear &&
|
||||
not repertory::utils::file::directory{path}.remove_recursively()) {
|
||||
repertory::utils::error::raise_error(
|
||||
|
@ -36,7 +36,14 @@ create_rocksdb(const repertory::app_config &cfg, const std::string &name,
|
||||
-> std::unique_ptr<rocksdb::TransactionDB> {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
auto path = repertory::utils::path::combine(cfg.get_data_directory(), {name});
|
||||
auto db_dir =
|
||||
repertory::utils::path::combine(cfg.get_data_directory(), {"db"});
|
||||
if (not repertory::utils::file::directory{db_dir}.create_directory()) {
|
||||
throw startup_exception(
|
||||
fmt::format("failed to create db directory|", db_dir));
|
||||
}
|
||||
|
||||
auto path = repertory::utils::path::combine(db_dir, {name});
|
||||
if (clear &&
|
||||
not repertory::utils::file::directory{path}.remove_recursively()) {
|
||||
repertory::utils::error::raise_error(
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "utils/db/sqlite/db_select.hpp"
|
||||
#include "utils/db/sqlite/db_update.hpp"
|
||||
#include "utils/error_utils.hpp"
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/path.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
||||
@ -51,9 +52,14 @@ const std::map<std::string, std::string> sql_create_tables = {
|
||||
|
||||
namespace repertory {
|
||||
sqlite_file_db::sqlite_file_db(const app_config &cfg) {
|
||||
db_ = utils::db::sqlite::create_db(
|
||||
utils::path::combine(cfg.get_data_directory(), {"provider_file.db"}),
|
||||
sql_create_tables);
|
||||
auto db_dir = utils::path::combine(cfg.get_data_directory(), {"db"});
|
||||
if (not utils::file::directory{db_dir}.create_directory()) {
|
||||
throw startup_exception(
|
||||
fmt::format("failed to create db directory|", db_dir));
|
||||
}
|
||||
|
||||
db_ = utils::db::sqlite::create_db(utils::path::combine(db_dir, {"file.db"}),
|
||||
sql_create_tables);
|
||||
}
|
||||
|
||||
sqlite_file_db::~sqlite_file_db() { db_.reset(); }
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "utils/db/sqlite/db_select.hpp"
|
||||
#include "utils/db/sqlite/db_update.hpp"
|
||||
#include "utils/error_utils.hpp"
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/path.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
||||
@ -75,9 +76,14 @@ const std::map<std::string, std::string> sql_create_tables{
|
||||
|
||||
namespace repertory {
|
||||
sqlite_file_mgr_db::sqlite_file_mgr_db(const app_config &cfg) {
|
||||
auto db_dir = utils::path::combine(cfg.get_data_directory(), {"db"});
|
||||
if (not utils::file::directory{db_dir}.create_directory()) {
|
||||
throw startup_exception(
|
||||
fmt::format("failed to create db directory|", db_dir));
|
||||
}
|
||||
|
||||
db_ = utils::db::sqlite::create_db(
|
||||
utils::path::combine(cfg.get_data_directory(), {"mgr.db"}),
|
||||
sql_create_tables);
|
||||
utils::path::combine(db_dir, {"file_mgr.db"}), sql_create_tables);
|
||||
}
|
||||
|
||||
sqlite_file_mgr_db::~sqlite_file_mgr_db() { db_.reset(); }
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "utils/db/sqlite/db_insert.hpp"
|
||||
#include "utils/db/sqlite/db_select.hpp"
|
||||
#include "utils/error_utils.hpp"
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/path.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
||||
@ -48,9 +49,14 @@ sqlite_meta_db::sqlite_meta_db(const app_config &cfg) {
|
||||
},
|
||||
};
|
||||
|
||||
db_ = utils::db::sqlite::create_db(
|
||||
utils::path::combine(cfg.get_data_directory(), {"provider_meta.db"}),
|
||||
sql_create_tables);
|
||||
auto db_dir = utils::path::combine(cfg.get_data_directory(), {"db"});
|
||||
if (not utils::file::directory{db_dir}.create_directory()) {
|
||||
throw startup_exception(
|
||||
fmt::format("failed to create db directory|", db_dir));
|
||||
}
|
||||
|
||||
db_ = utils::db::sqlite::create_db(utils::path::combine(db_dir, {"meta.db"}),
|
||||
sql_create_tables);
|
||||
}
|
||||
|
||||
sqlite_meta_db::~sqlite_meta_db() { db_.reset(); }
|
||||
|
Loading…
x
Reference in New Issue
Block a user