From 7608c2b18b8ec4854eaeff90da3b03ce3631fe45 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Sun, 14 Apr 2024 21:44:40 +0200 Subject: [PATCH] core: migrating the database Signed-off-by: Vincenzo Palazzo --- coffee_core/src/coffee.rs | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/coffee_core/src/coffee.rs b/coffee_core/src/coffee.rs index a750b0d..e7ff10d 100644 --- a/coffee_core/src/coffee.rs +++ b/coffee_core/src/coffee.rs @@ -105,8 +105,7 @@ impl CoffeeManager { .map(|store| { self.config = store.config; }); - // FIXME: check if this exist in a better wai - let _ = self + let global_repositories = self .storage .load::>("repositories") .await @@ -120,6 +119,34 @@ impl CoffeeManager { }); }); + if let Ok(_) = global_repositories { + // HACK: this should be done with the nurse command, but + // due that currently migrating the database with the nurse + // logic is a little bit tricky we do this hack and we try + // to move on, but if you are looking something to do in coffee + // it is possible to take this problem and design a solution. + // FIXME: add the drop method inside nosql_db + } + + let local_repositories = self + .storage + .load::>(&format!( + "{}/repositories", + self.config.network + )) + .await; + if let Ok(repos) = local_repositories { + // FIXME: till we are not able to remove a key from + // the database + self.repos.clear(); + repos.iter().for_each(|repo| match repo.1.kind { + Kind::Git => { + let repo = Github::from(repo.1); + self.repos.insert(repo.name(), Box::new(repo)); + } + }); + } + if let Err(err) = self.coffee_cln_config.parse() { log::error!("{}", err.cause); } @@ -192,7 +219,10 @@ impl CoffeeManager { .store(&self.config.network, &store_info) .await?; self.storage - .store("repositories", &store_info.repositories) + .store( + &format!("{}/repositories", self.config.network), + &store_info.repositories, + ) .await?; Ok(()) }