radicle: Consolidate databases

Instead of having a routing database, and an addresses database,
consolidate that in a single database called `node.db`.

We also simplify database access, by providing a single type for opening
the database, and use traits to access the various functions.

We create a new `seed::Store` that has seed-related methods split out of
the `address::Store`.

Note that tracking is still in its own database currently, as it isn't
ephemeral state. This makes it easy to delete the new `node.db` without
risk of losing any important information.

To avoid renaming all database methods, we create a `Stores` wrapper
that allows us to access routing, addresses, seeds etc. without type
ambiguity.

This is a breaking change and requires `addresses.db` and `routing.db`
to be deleted.
This commit is contained in:
cloudhead
2023-11-30 13:00:59 +01:00
parent 80c1bb5b22
commit 0a645b797b
5 changed files with 10 additions and 18 deletions
+2 -2
View File
@@ -62,8 +62,8 @@ impl Context {
let delegates = doc.delegates;
let issues = issue::Issues::open(&repo)?.counts()?;
let patches = patch::Patches::open(&repo)?.counts()?;
let routing = &self.profile.routing()?;
let trackings = routing.count(&id).unwrap_or_default();
let db = &self.profile.database()?;
let trackings = db.count(&id).unwrap_or_default();
Ok(project::Info {
payload,
+2 -2
View File
@@ -74,9 +74,9 @@ pub enum Error {
#[error(transparent)]
TrackingStore(#[from] radicle::node::tracking::store::Error),
/// Routing store error.
/// Node database error.
#[error(transparent)]
RoutingStore(#[from] radicle::node::routing::Error),
Database(#[from] radicle::node::db::Error),
/// Node error.
#[error(transparent)]
+2 -2
View File
@@ -38,7 +38,7 @@ async fn delegates_projects_handler(
let page = page.unwrap_or(0);
let per_page = per_page.unwrap_or(10);
let storage = &ctx.profile.storage;
let routing = &ctx.profile.routing()?;
let db = &ctx.profile.database()?;
let mut projects = storage
.repositories()?
.into_iter()
@@ -78,7 +78,7 @@ async fn delegates_projects_handler(
};
let delegates = id.doc.delegates;
let trackings = routing.count(&id.rid).unwrap_or_default();
let trackings = db.count(&id.rid).unwrap_or_default();
Some(Info {
payload,
+2 -2
View File
@@ -83,7 +83,7 @@ async fn project_root_handler(
let page = page.unwrap_or(0);
let per_page = per_page.unwrap_or(10);
let storage = &ctx.profile.storage;
let routing = &ctx.profile.routing()?;
let db = &ctx.profile.database()?;
let mut projects = storage
.repositories()?
.into_iter()
@@ -119,7 +119,7 @@ async fn project_root_handler(
return None;
};
let delegates = id.doc.delegates;
let trackings = routing.count(&id.rid).unwrap_or_default();
let trackings = db.count(&id.rid).unwrap_or_default();
Some(Info {
payload,
+2 -10
View File
@@ -19,9 +19,6 @@ use radicle::crypto::{KeyPair, Seed, Signer};
use radicle::git::{raw as git2, RefString};
use radicle::identity::Visibility;
use radicle::node;
use radicle::node::address as AddressStore;
use radicle::node::routing as RoutingStore;
use radicle::node::tracking::store as TrackingStore;
use radicle::profile;
use radicle::profile::Home;
use radicle::storage::ReadStorage;
@@ -96,15 +93,10 @@ pub fn contributor(dir: &Path) -> Context {
fn seed_with_signer<G: Signer>(dir: &Path, profile: radicle::Profile, signer: &G) -> Context {
const DEFAULT_BRANCH: &str = "master";
let tracking_db = dir.join("radicle").join("node").join("tracking.db");
let routing_db = dir.join("radicle").join("node").join("routing.db");
let addresses_db = dir.join("radicle").join("node").join("addresses.db");
crate::logger::init().ok();
TrackingStore::Config::open(tracking_db).unwrap();
RoutingStore::Table::open(routing_db).unwrap();
AddressStore::Book::open(addresses_db).unwrap();
profile.tracking_mut().unwrap();
profile.database_mut().unwrap(); // Create the database.
let workdir = dir.join("hello-world-private");
fs::create_dir_all(&workdir).unwrap();