diff --git a/crates/storage/db/src/mdbx.rs b/crates/storage/db/src/mdbx.rs index d6947e10b..c0e11079f 100644 --- a/crates/storage/db/src/mdbx.rs +++ b/crates/storage/db/src/mdbx.rs @@ -1,6 +1,6 @@ //! Bindings for [MDBX](https://libmdbx.dqdkfa.ru/). -use crate::is_database_empty; +use crate::{is_database_empty, TableSet, Tables}; use eyre::Context; use std::path::Path; @@ -28,12 +28,21 @@ pub fn create_db>(path: P, args: DatabaseArguments) -> eyre::Resu Ok(DatabaseEnv::open(rpath, DatabaseEnvKind::RW, args)?) } -/// Opens up an existing database or creates a new one at the specified path. Creates tables if -/// necessary. Read/Write mode. +/// Opens up an existing database or creates a new one at the specified path. Creates tables defined +/// in [`Tables`] if necessary. Read/Write mode. pub fn init_db>(path: P, args: DatabaseArguments) -> eyre::Result { + init_db_for::(path, args) +} + +/// Opens up an existing database or creates a new one at the specified path. Creates tables defined +/// in the given [`TableSet`] if necessary. Read/Write mode. +pub fn init_db_for, TS: TableSet>( + path: P, + args: DatabaseArguments, +) -> eyre::Result { let client_version = args.client_version().clone(); let db = create_db(path, args)?; - db.create_tables()?; + db.create_tables_for::()?; db.record_client_version(client_version)?; Ok(db) }