aboutsummaryrefslogtreecommitdiffstats
path: root/atuin-client/src/history
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@elliehuxtable.com>2024-01-29 16:38:24 +0000
committerGitHub <noreply@github.com>2024-01-29 16:38:24 +0000
commit366b8ea97bbe36ad5e3dd8d45f1e787ee2a7f223 (patch)
treed889d76c73176def805c45fd10f72d4cd3a5a93a /atuin-client/src/history
parenttest: add multi-user integration tests (#1648) (diff)
downloadatuin-366b8ea97bbe36ad5e3dd8d45f1e787ee2a7f223.zip
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
Diffstat (limited to 'atuin-client/src/history')
-rw-r--r--atuin-client/src/history/store.rs30
1 files changed, 29 insertions, 1 deletions
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)]