Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(doctor): report sqlite version #2075

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/atuin-client/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ impl Sqlite {
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<()> {
debug!("running sqlite database setup");

Expand Down
2 changes: 1 addition & 1 deletion crates/atuin/src/command/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl Cmd {
Ok(())
}

Self::Doctor => doctor::run(&settings),
Self::Doctor => doctor::run(&settings).await,

Self::DefaultConfig => {
default_config::run();
Expand Down
22 changes: 17 additions & 5 deletions crates/atuin/src/command/client/doctor.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<SyncInfo>,

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();

Expand All @@ -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,
}
}
}
Expand All @@ -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(),
}
Expand Down Expand Up @@ -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);

Expand Down
Loading