From 96163c5591d21bb8338828f765a6159ad5bf29a1 Mon Sep 17 00:00:00 2001 From: Xavier Vello Date: Mon, 3 Jun 2024 11:51:31 +0200 Subject: [PATCH] feat(doctor): report sqlite version (#2075) --- crates/atuin-client/src/database.rs | 6 ++++++ crates/atuin/src/command/client.rs | 2 +- crates/atuin/src/command/client/doctor.rs | 22 +++++++++++++++++----- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/crates/atuin-client/src/database.rs b/crates/atuin-client/src/database.rs index c443da37..d01dadb4 100644 --- a/crates/atuin-client/src/database.rs +++ b/crates/atuin-client/src/database.rs @@ -154,6 +154,12 @@ impl Sqlite { Ok(Self { pool }) } + pub async fn sqlite_version(&self) -> Result { + sqlx::query_scalar("SELECT sqlite_version()") + .fetch_one(&self.pool) + .await + } + async fn setup_db(pool: &SqlitePool) -> Result<()> { debug!("running sqlite database setup"); diff --git a/crates/atuin/src/command/client.rs b/crates/atuin/src/command/client.rs index 180ced10..80f32929 100644 --- a/crates/atuin/src/command/client.rs +++ b/crates/atuin/src/command/client.rs @@ -148,7 +148,7 @@ impl Cmd { Ok(()) } - Self::Doctor => doctor::run(&settings), + Self::Doctor => doctor::run(&settings).await, Self::DefaultConfig => { default_config::run(); diff --git a/crates/atuin/src/command/client/doctor.rs b/crates/atuin/src/command/client/doctor.rs index 48659ed1..4e7bc170 100644 --- a/crates/atuin/src/command/client/doctor.rs +++ b/crates/atuin/src/command/client/doctor.rs @@ -1,6 +1,7 @@ use std::process::Command; use std::{env, path::PathBuf, str::FromStr}; +use atuin_client::database::Sqlite; use atuin_client::settings::Settings; use atuin_common::shell::{shell_name, Shell}; use colored::Colorize; @@ -261,10 +262,12 @@ struct AtuinInfo { /// Whether the main Atuin sync server is in use /// I'm just calling it Atuin Cloud for lack of a better name atm pub sync: Option, + + pub sqlite_version: String, } impl AtuinInfo { - pub fn new(settings: &Settings) -> Self { + pub async fn new(settings: &Settings) -> Self { let session_path = settings.session_path.as_str(); let logged_in = PathBuf::from(session_path).exists(); @@ -274,9 +277,18 @@ impl AtuinInfo { None }; + let sqlite_version = match Sqlite::new("sqlite::memory:", 0.1).await { + Ok(db) => db + .sqlite_version() + .await + .unwrap_or_else(|_| "unknown".to_string()), + Err(_) => "error".to_string(), + }; + Self { version: crate::VERSION.to_string(), sync, + sqlite_version, } } } @@ -289,9 +301,9 @@ struct DoctorDump { } impl DoctorDump { - pub fn new(settings: &Settings) -> Self { + pub async fn new(settings: &Settings) -> Self { Self { - atuin: AtuinInfo::new(settings), + atuin: AtuinInfo::new(settings).await, shell: ShellInfo::new(), system: SystemInfo::new(), } @@ -330,10 +342,10 @@ fn checks(info: &DoctorDump) { } } -pub fn run(settings: &Settings) -> Result<()> { +pub async fn run(settings: &Settings) -> Result<()> { println!("{}", "Atuin Doctor".bold()); println!("Checking for diagnostics"); - let dump = DoctorDump::new(settings); + let dump = DoctorDump::new(settings).await; checks(&dump);