From 366b8ea97bbe36ad5e3dd8d45f1e787ee2a7f223 Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Mon, 29 Jan 2024 16:38:24 +0000 Subject: feat: automatically init history store when record sync is enabled (#1634) * add support for getting the total length of a store * tidy up sync * auto call init if history is ahead * fix import order, key regen * fix import order, key regen * do not delete key when user deletes account * message output * remote init store command; this is now automatic * should probs make that function return u64 at some point --- atuin-client/src/history/store.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'atuin-client/src/history') diff --git a/atuin-client/src/history/store.rs b/atuin-client/src/history/store.rs index 442da45d..0a2a2312 100644 --- a/atuin-client/src/history/store.rs +++ b/atuin-client/src/history/store.rs @@ -4,7 +4,7 @@ use eyre::{bail, eyre, Result}; use rmp::decode::Bytes; use crate::{ - database::Database, + database::{self, Database}, record::{encryption::PASETO_V4, sqlite_store::SqliteStore, store::Store}, }; use atuin_common::record::{DecryptedData, Host, HostId, Record, RecordId, RecordIdx}; @@ -255,6 +255,34 @@ impl HistoryStore { Ok(ret) } + + pub async fn init_store(&self, context: database::Context, db: &impl Database) -> Result<()> { + println!("Importing all history.db data into records.db"); + + println!("Fetching history from old database"); + let history = db.list(&[], &context, None, false, true).await?; + + println!("Fetching history already in store"); + let store_ids = self.history_ids().await?; + + for i in history { + println!("loaded {}", i.id); + + if store_ids.contains(&i.id) { + println!("skipping {} - already exists", i.id); + continue; + } + + if i.deleted_at.is_some() { + self.push(i.clone()).await?; + self.delete(i.id).await?; + } else { + self.push(i).await?; + } + } + + Ok(()) + } } #[cfg(test)] -- cgit v1.3.1