Skip to content

Commit 8beb636

Browse files
committed
Add migration for #529
1 parent bff7bac commit 8beb636

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

lib/src/db.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl Db {
8989
pub fn init(path: &std::path::Path, server_url: String) -> AtomicResult<Db> {
9090
let db = sled::open(path).map_err(|e|format!("Failed opening DB at this location: {:?} . Is another instance of Atomic Server running? {}", path, e))?;
9191
let resources = db.open_tree("resources_v1").map_err(|e|format!("Failed building resources. Your DB might be corrupt. Go back to a previous version and export your data. {}", e))?;
92-
let reference_index = db.open_tree("reference_index")?;
92+
let reference_index = db.open_tree("reference_index_v1")?;
9393
let query_index = db.open_tree("members_index")?;
9494
let prop_val_sub_index = db.open_tree("prop_val_sub_index")?;
9595
let watched_queries = db.open_tree("watched_queries")?;

lib/src/db/migrations.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ Therefore, we need migrations to convert the old schema to the new one.
1212
- Update the Tree key used in [Db::init]
1313
*/
1414

15-
use crate::{errors::AtomicResult, Db};
15+
use crate::{errors::AtomicResult, Db, Storelike};
1616

1717
/// Checks the current version(s) of the internal Store, and performs migrations if needed.
1818
pub fn migrate_maybe(store: &Db) -> AtomicResult<()> {
1919
for tree in store.db.tree_names() {
2020
match String::from_utf8_lossy(&tree).as_ref() {
2121
// Add migrations for outdated Trees to this list
2222
"resources" => v0_to_v1(store)?,
23+
"reference_index" => ref_v0_to_v1(store)?,
2324
_other => {}
2425
}
2526
}
@@ -71,3 +72,12 @@ fn v0_to_v1(store: &Db) -> AtomicResult<()> {
7172
tracing::warn!("Finished migration of {} resources", count);
7273
Ok(())
7374
}
75+
76+
/// Add `prop_val_sub` index
77+
fn ref_v0_to_v1(store: &Db) -> AtomicResult<()> {
78+
tracing::warn!("Rebuilding indexes...");
79+
store.db.drop_tree("reference_index")?;
80+
store.build_index(true)?;
81+
tracing::warn!("Rebuilding index finished!");
82+
Ok(())
83+
}

lib/src/storelike.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ impl Query {
377377
sort_by: None,
378378
sort_desc: false,
379379
include_external: false,
380-
include_nested: false,
380+
include_nested: true,
381381
for_agent: None,
382382
}
383383
}
@@ -399,6 +399,12 @@ impl Query {
399399
}
400400
}
401401

402+
impl Default for Query {
403+
fn default() -> Self {
404+
Self::new()
405+
}
406+
}
407+
402408
pub struct QueryResult {
403409
pub subjects: Vec<String>,
404410
pub resources: Vec<Resource>,

0 commit comments

Comments
 (0)