Skip to content
Snippets Groups Projects
Commit 64637a40 authored by Éloïs's avatar Éloïs
Browse files

[feat] dex:migrate: clear DBs before migration

parent 8caa8fe5
No related branches found
No related tags found
1 merge request!1335Gva proto 2
...@@ -28,6 +28,10 @@ pub(crate) fn migrate(profile_path: PathBuf) -> anyhow::Result<()> { ...@@ -28,6 +28,10 @@ pub(crate) fn migrate(profile_path: PathBuf) -> anyhow::Result<()> {
let start_time = Instant::now(); let start_time = Instant::now();
let dbs = duniter_dbs::open_dbs(Some(profile_path.as_path())); let dbs = duniter_dbs::open_dbs(Some(profile_path.as_path()));
// Clear bc_db and gva_db
dbs.bc_db.clear()?;
dbs.gva_db.clear()?;
let data_path = profile_path.join(crate::DATA_DIR); let data_path = profile_path.join(crate::DATA_DIR);
let duniter_js_db = BcV1Db::<LevelDb>::open(LevelDbConf { let duniter_js_db = BcV1Db::<LevelDb>::open(LevelDbConf {
db_path: data_path.as_path().join("leveldb"), db_path: data_path.as_path().join("leveldb"),
......
...@@ -141,6 +141,7 @@ macro_rules! db_schema { ...@@ -141,6 +141,7 @@ macro_rules! db_schema {
$(type [<$col_name ColRw>]: DbCollectionRw;)* $(type [<$col_name ColRw>]: DbCollectionRw;)*
type DbRo: Sized; type DbRo: Sized;
fn clear(&self) -> KvResult<()>;
fn get_ro_handler(&self) -> Self::DbRo; fn get_ro_handler(&self) -> Self::DbRo;
fn open( fn open(
backend_conf: <<Self as [<$db_name DbWritable>]>::Backend as kv_typed::backend::Backend>::Conf, backend_conf: <<Self as [<$db_name DbWritable>]>::Backend as kv_typed::backend::Backend>::Conf,
...@@ -156,6 +157,11 @@ macro_rules! db_schema { ...@@ -156,6 +157,11 @@ macro_rules! db_schema {
$(type [<$col_name ColRw>] = ColRw<B::Col, [<$col_name Event>]>;)* $(type [<$col_name ColRw>] = ColRw<B::Col, [<$col_name Event>]>;)*
type DbRo = [<$db_name DbRo>]<B>; type DbRo = [<$db_name DbRo>]<B>;
#[inline(always)]
fn clear(&self) -> KvResult<()> {
$(self.collections.[<$col_name:snake>].clear()?;)*
Ok(())
}
#[inline(always)] #[inline(always)]
fn get_ro_handler(&self) -> Self::DbRo { fn get_ro_handler(&self) -> Self::DbRo {
[<$db_name DbRo>] { [<$db_name DbRo>] {
...@@ -182,11 +188,15 @@ macro_rules! db_schema { ...@@ -182,11 +188,15 @@ macro_rules! db_schema {
}, },
}) })
} }
#[inline(always)]
fn save(&self) -> KvResult<()> { fn save(&self) -> KvResult<()> {
$(self.collections.[<$col_name:snake>].save()?;)* $(self.collections.[<$col_name:snake>].save()?;)*
Ok(()) Ok(())
} }
$(fn [<$col_name:snake _write>](&self) -> &ColRw<B::Col, [<$col_name Event>]> { &self.collections.[<$col_name:snake>] })* $(
#[inline(always)]
fn [<$col_name:snake _write>](&self) -> &ColRw<B::Col, [<$col_name Event>]> { &self.collections.[<$col_name:snake>] }
)*
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment