aboutsummaryrefslogtreecommitdiffstats
path: root/crates/turtle/src/atuin_client/meta.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-06-11 16:10:29 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-06-11 16:10:29 +0200
commit97f207b771b94c5285faae4810d6eeda1b78926b (patch)
tree4482544233c30e0e9a62be6afcfe92c8e01b0a50 /crates/turtle/src/atuin_client/meta.rs
parentchore: Remove all `pub`s (diff)
downloadatuin-97f207b771b94c5285faae4810d6eeda1b78926b.zip
chore(server): Simplify the database support
Diffstat (limited to 'crates/turtle/src/atuin_client/meta.rs')
-rw-r--r--crates/turtle/src/atuin_client/meta.rs156
1 files changed, 7 insertions, 149 deletions
diff --git a/crates/turtle/src/atuin_client/meta.rs b/crates/turtle/src/atuin_client/meta.rs
index 502d7421..92902c08 100644
--- a/crates/turtle/src/atuin_client/meta.rs
+++ b/crates/turtle/src/atuin_client/meta.rs
@@ -7,22 +7,12 @@ use eyre::{Result, eyre};
use sqlx::sqlite::{SqliteConnectOptions, SqliteJournalMode, SqlitePool, SqlitePoolOptions};
use time::{OffsetDateTime, format_description::well_known::Rfc3339};
use tokio::sync::OnceCell;
-use tracing::{debug, warn};
+use tracing::debug;
use uuid::Uuid;
-// Filenames for the legacy plain-text files that we migrate from.
-const LEGACY_HOST_ID_FILENAME: &str = "host_id";
-const LEGACY_LAST_SYNC_FILENAME: &str = "last_sync_time";
-const LEGACY_LAST_VERSION_CHECK_FILENAME: &str = "last_version_check_time";
-const LEGACY_LATEST_VERSION_FILENAME: &str = "latest_version";
-const LEGACY_SESSION_FILENAME: &str = "session";
-
const KEY_HOST_ID: &str = "host_id";
const KEY_LAST_SYNC: &str = "last_sync_time";
-const KEY_LAST_VERSION_CHECK: &str = "last_version_check_time";
-const KEY_LATEST_VERSION: &str = "latest_version";
const KEY_SESSION: &str = "session";
-const KEY_FILES_MIGRATED: &str = "files_migrated";
pub(crate) struct MetaStore {
pool: SqlitePool,
@@ -77,10 +67,6 @@ impl MetaStore {
cached_host_id: OnceCell::const_new(),
};
- if !is_memory {
- store.migrate_files().await?;
- }
-
Ok(store)
}
@@ -97,8 +83,12 @@ impl MetaStore {
pub(crate) async fn set(&self, key: &str, value: &str) -> Result<()> {
sqlx::query(
- "INSERT INTO meta (key, value, updated_at) VALUES (?1, ?2, strftime('%s', 'now'))
- ON CONFLICT(key) DO UPDATE SET value = ?2, updated_at = strftime('%s', 'now')",
+ "
+ INSERT INTO meta (key, value, updated_at)
+ VALUES (?1, ?2, strftime('%s', 'now'))
+ ON CONFLICT(key) DO UPDATE
+ SET value = ?2, updated_at = strftime('%s', 'now')
+ ",
)
.bind(key)
.bind(value)
@@ -153,29 +143,6 @@ impl MetaStore {
.await
}
- pub(crate) async fn last_version_check(&self) -> Result<OffsetDateTime> {
- match self.get(KEY_LAST_VERSION_CHECK).await? {
- Some(v) => Ok(OffsetDateTime::parse(v.as_str(), &Rfc3339)?),
- None => Ok(OffsetDateTime::UNIX_EPOCH),
- }
- }
-
- pub(crate) async fn save_version_check_time(&self) -> Result<()> {
- self.set(
- KEY_LAST_VERSION_CHECK,
- OffsetDateTime::now_utc().format(&Rfc3339)?.as_str(),
- )
- .await
- }
-
- pub(crate) async fn latest_version(&self) -> Result<Option<String>> {
- self.get(KEY_LATEST_VERSION).await
- }
-
- pub(crate) async fn save_latest_version(&self, version: &str) -> Result<()> {
- self.set(KEY_LATEST_VERSION, version).await
- }
-
pub(crate) async fn session_token(&self) -> Result<Option<String>> {
self.get(KEY_SESSION).await
}
@@ -191,90 +158,6 @@ impl MetaStore {
pub(crate) async fn logged_in(&self) -> Result<bool> {
Ok(self.session_token().await?.is_some())
}
-
- // File migration: on first open, migrate old plain-text files into the database.
- // Old files are left in place for safe downgrades.
-
- async fn migrate_files(&self) -> Result<()> {
- if self.get(KEY_FILES_MIGRATED).await?.is_some() {
- return Ok(());
- }
-
- let data_dir = crate::atuin_client::settings::Settings::effective_data_dir();
-
- // host_id — validate as UUID
- let host_id_path = data_dir.join(LEGACY_HOST_ID_FILENAME);
- if host_id_path.exists()
- && let Ok(value) = fs_err::read_to_string(&host_id_path)
- {
- let value = value.trim();
- if !value.is_empty() {
- if Uuid::from_str(value).is_ok() {
- self.set(KEY_HOST_ID, value).await?;
- } else {
- warn!("skipping migration of host_id: invalid UUID {value:?}");
- }
- }
- }
-
- // last_sync_time — validate as RFC3339
- let sync_path = data_dir.join(LEGACY_LAST_SYNC_FILENAME);
- if sync_path.exists()
- && let Ok(value) = fs_err::read_to_string(&sync_path)
- {
- let value = value.trim();
- if !value.is_empty() {
- if OffsetDateTime::parse(value, &Rfc3339).is_ok() {
- self.set(KEY_LAST_SYNC, value).await?;
- } else {
- warn!("skipping migration of last_sync_time: invalid RFC3339 {value:?}");
- }
- }
- }
-
- // last_version_check_time — validate as RFC3339
- let version_check_path = data_dir.join(LEGACY_LAST_VERSION_CHECK_FILENAME);
- if version_check_path.exists()
- && let Ok(value) = fs_err::read_to_string(&version_check_path)
- {
- let value = value.trim();
- if !value.is_empty() {
- if OffsetDateTime::parse(value, &Rfc3339).is_ok() {
- self.set(KEY_LAST_VERSION_CHECK, value).await?;
- } else {
- warn!(
- "skipping migration of last_version_check_time: invalid RFC3339 {value:?}"
- );
- }
- }
- }
-
- // latest_version — no strict validation, just non-empty
- let latest_version_path = data_dir.join(LEGACY_LATEST_VERSION_FILENAME);
- if latest_version_path.exists()
- && let Ok(value) = fs_err::read_to_string(&latest_version_path)
- {
- let value = value.trim();
- if !value.is_empty() {
- self.set(KEY_LATEST_VERSION, value).await?;
- }
- }
-
- // session token — no strict validation, just non-empty
- let session_path = data_dir.join(LEGACY_SESSION_FILENAME);
- if session_path.exists()
- && let Ok(value) = fs_err::read_to_string(&session_path)
- {
- let value = value.trim();
- if !value.is_empty() {
- self.set(KEY_SESSION, value).await?;
- }
- }
-
- self.set(KEY_FILES_MIGRATED, "true").await?;
-
- Ok(())
- }
}
#[cfg(test)]
@@ -324,18 +207,6 @@ mod tests {
}
#[tokio::test]
- async fn test_version_check_time() {
- let store = new_test_store().await;
-
- let t = store.last_version_check().await.unwrap();
- assert_eq!(t, OffsetDateTime::UNIX_EPOCH);
-
- store.save_version_check_time().await.unwrap();
- let t = store.last_version_check().await.unwrap();
- assert!(t > OffsetDateTime::UNIX_EPOCH);
- }
-
- #[tokio::test]
async fn test_session_crud() {
let store = new_test_store().await;
@@ -352,17 +223,4 @@ mod tests {
store.delete_session().await.unwrap();
assert!(!store.logged_in().await.unwrap());
}
-
- #[tokio::test]
- async fn test_latest_version() {
- let store = new_test_store().await;
-
- assert_eq!(store.latest_version().await.unwrap(), None);
-
- store.save_latest_version("1.2.3").await.unwrap();
- assert_eq!(
- store.latest_version().await.unwrap(),
- Some("1.2.3".to_string())
- );
- }
}