make each db backend responsible for its own setup

RocksDB automatically creates parent directories already. SQLite doesn't
create parent directories, only the db file if it didn't exist.
This commit is contained in:
Charles Hall 2024-10-08 19:16:18 -07:00
parent 5e3825c37c
commit f5ba3e3062
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
2 changed files with 3 additions and 11 deletions

View file

@ -3,7 +3,6 @@ use std::{
fs,
io::Write,
mem::size_of,
path::Path,
sync::Arc,
};
@ -241,16 +240,6 @@ impl KeyValueDatabase {
"Compiled without support for any databases",
));
if !Path::new(&config.database.path).exists() {
fs::create_dir_all(&config.database.path).map_err(|_| {
Error::BadConfig(
"Database folder doesn't exists and couldn't be created \
(e.g. due to missing permissions). Please create the \
database folder yourself.",
)
})?;
}
let x: Arc<dyn KeyValueDatabaseEngine> = match config.database.backend {
#[cfg(feature = "sqlite")]
DatabaseBackend::Sqlite => {

View file

@ -1,5 +1,6 @@
use std::{
cell::RefCell,
fs,
future::Future,
path::{Path, PathBuf},
pin::Pin,
@ -67,6 +68,8 @@ pub(crate) struct Engine {
impl Engine {
pub(crate) fn open(config: &Config) -> Result<Self> {
fs::create_dir_all(&config.database.path)?;
let path = Path::new(&config.database.path).join("sqlite.db");
// calculates cache-size per permanent connection