Skip to content

Commit 7608c2b

Browse files
core: migrating the database
Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent 99633ee commit 7608c2b

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

coffee_core/src/coffee.rs

+33-3
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ impl CoffeeManager {
105105
.map(|store| {
106106
self.config = store.config;
107107
});
108-
// FIXME: check if this exist in a better wai
109-
let _ = self
108+
let global_repositories = self
110109
.storage
111110
.load::<HashMap<RepoName, RepositoryInfo>>("repositories")
112111
.await
@@ -120,6 +119,34 @@ impl CoffeeManager {
120119
});
121120
});
122121

122+
if let Ok(_) = global_repositories {
123+
// HACK: this should be done with the nurse command, but
124+
// due that currently migrating the database with the nurse
125+
// logic is a little bit tricky we do this hack and we try
126+
// to move on, but if you are looking something to do in coffee
127+
// it is possible to take this problem and design a solution.
128+
// FIXME: add the drop method inside nosql_db
129+
}
130+
131+
let local_repositories = self
132+
.storage
133+
.load::<HashMap<RepoName, RepositoryInfo>>(&format!(
134+
"{}/repositories",
135+
self.config.network
136+
))
137+
.await;
138+
if let Ok(repos) = local_repositories {
139+
// FIXME: till we are not able to remove a key from
140+
// the database
141+
self.repos.clear();
142+
repos.iter().for_each(|repo| match repo.1.kind {
143+
Kind::Git => {
144+
let repo = Github::from(repo.1);
145+
self.repos.insert(repo.name(), Box::new(repo));
146+
}
147+
});
148+
}
149+
123150
if let Err(err) = self.coffee_cln_config.parse() {
124151
log::error!("{}", err.cause);
125152
}
@@ -192,7 +219,10 @@ impl CoffeeManager {
192219
.store(&self.config.network, &store_info)
193220
.await?;
194221
self.storage
195-
.store("repositories", &store_info.repositories)
222+
.store(
223+
&format!("{}/repositories", self.config.network),
224+
&store_info.repositories,
225+
)
196226
.await?;
197227
Ok(())
198228
}

0 commit comments

Comments
 (0)