Skip to content

Commit

Permalink
core: migrating the database
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed Apr 14, 2024
1 parent 99633ee commit 7608c2b
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions coffee_core/src/coffee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<HashMap<RepoName, RepositoryInfo>>("repositories")
.await
Expand All @@ -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::<HashMap<RepoName, RepositoryInfo>>(&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);
}
Expand Down Expand Up @@ -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(())
}
Expand Down

0 comments on commit 7608c2b

Please sign in to comment.