feat(doctor): report sqlite version (#2075)

This commit is contained in:
Xavier Vello 2024-06-03 11:51:31 +02:00 committed by GitHub
parent 928dce4a8c
commit 96163c5591
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 6 deletions

View File

@ -154,6 +154,12 @@ impl Sqlite {
Ok(Self { pool }) Ok(Self { pool })
} }
pub async fn sqlite_version(&self) -> Result<String> {
sqlx::query_scalar("SELECT sqlite_version()")
.fetch_one(&self.pool)
.await
}
async fn setup_db(pool: &SqlitePool) -> Result<()> { async fn setup_db(pool: &SqlitePool) -> Result<()> {
debug!("running sqlite database setup"); debug!("running sqlite database setup");

View File

@ -148,7 +148,7 @@ impl Cmd {
Ok(()) Ok(())
} }
Self::Doctor => doctor::run(&settings), Self::Doctor => doctor::run(&settings).await,
Self::DefaultConfig => { Self::DefaultConfig => {
default_config::run(); default_config::run();

View File

@ -1,6 +1,7 @@
use std::process::Command; use std::process::Command;
use std::{env, path::PathBuf, str::FromStr}; use std::{env, path::PathBuf, str::FromStr};
use atuin_client::database::Sqlite;
use atuin_client::settings::Settings; use atuin_client::settings::Settings;
use atuin_common::shell::{shell_name, Shell}; use atuin_common::shell::{shell_name, Shell};
use colored::Colorize; use colored::Colorize;
@ -261,10 +262,12 @@ struct AtuinInfo {
/// Whether the main Atuin sync server is in use /// Whether the main Atuin sync server is in use
/// I'm just calling it Atuin Cloud for lack of a better name atm /// I'm just calling it Atuin Cloud for lack of a better name atm
pub sync: Option<SyncInfo>, pub sync: Option<SyncInfo>,
pub sqlite_version: String,
} }
impl AtuinInfo { impl AtuinInfo {
pub fn new(settings: &Settings) -> Self { pub async fn new(settings: &Settings) -> Self {
let session_path = settings.session_path.as_str(); let session_path = settings.session_path.as_str();
let logged_in = PathBuf::from(session_path).exists(); let logged_in = PathBuf::from(session_path).exists();
@ -274,9 +277,18 @@ impl AtuinInfo {
None 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 { Self {
version: crate::VERSION.to_string(), version: crate::VERSION.to_string(),
sync, sync,
sqlite_version,
} }
} }
} }
@ -289,9 +301,9 @@ struct DoctorDump {
} }
impl DoctorDump { impl DoctorDump {
pub fn new(settings: &Settings) -> Self { pub async fn new(settings: &Settings) -> Self {
Self { Self {
atuin: AtuinInfo::new(settings), atuin: AtuinInfo::new(settings).await,
shell: ShellInfo::new(), shell: ShellInfo::new(),
system: SystemInfo::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!("{}", "Atuin Doctor".bold());
println!("Checking for diagnostics"); println!("Checking for diagnostics");
let dump = DoctorDump::new(settings); let dump = DoctorDump::new(settings).await;
checks(&dump); checks(&dump);