From d07e1fd2791de15f62de33e8e3fcdd064ab6e427 Mon Sep 17 00:00:00 2001 From: "Rodrigo Rodriguez (Pragmatismo)" Date: Fri, 7 Nov 2025 09:37:45 -0300 Subject: [PATCH] fix: add PostgreSQL auto-start and silence unused variable warnings Added a check in `BootstrapManager` to detect if PostgreSQL is running and attempt to start the "tables" component automatically if not. Also prefixed unused variables and struct fields with underscores in compiler, session, and model modules to suppress warnings and improve code clarity. --- src/basic/compiler/mod.rs | 4 ++-- src/bootstrap/mod.rs | 25 ++++++++++++++++++++++++- src/session/mod.rs | 2 +- src/shared/models.rs | 2 +- src/ui/stream.rs | 26 ++++++++++++++++++++++++++ 5 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 src/ui/stream.rs diff --git a/src/basic/compiler/mod.rs b/src/basic/compiler/mod.rs index cab05a69b..0f9ab8415 100644 --- a/src/basic/compiler/mod.rs +++ b/src/basic/compiler/mod.rs @@ -143,7 +143,7 @@ impl BasicCompiler { Ok(CompilationResult { mcp_tool: mcp_json, - openai_tool: tool_json, + _openai_tool: tool_json, }) } @@ -438,5 +438,5 @@ impl BasicCompiler { #[derive(Debug)] pub struct CompilationResult { pub mcp_tool: Option, - pub openai_tool: Option, + pub _openai_tool: Option, } diff --git a/src/bootstrap/mod.rs b/src/bootstrap/mod.rs index 3c768c3bb..11a2aab6e 100644 --- a/src/bootstrap/mod.rs +++ b/src/bootstrap/mod.rs @@ -4,7 +4,7 @@ use crate::shared::utils::establish_pg_connection; use anyhow::Result; use diesel::{connection::SimpleConnection}; use dotenvy::dotenv; -use log::{debug, error, info, trace}; +use log::{debug, error, info, trace, warn}; use aws_sdk_s3::Client; use aws_config::BehaviorVersion; use rand::distr::Alphanumeric; @@ -26,11 +26,34 @@ pub struct BootstrapManager { } impl BootstrapManager { + fn is_postgres_running() -> bool { + match Command::new("pg_isready").arg("-q").status() { + Ok(status) => status.success(), + Err(_) => { + // fallback check using pgrep + Command::new("pgrep").arg("postgres").output().map(|o| !o.stdout.is_empty()).unwrap_or(false) + } + } + } + pub async fn new(install_mode: InstallMode, tenant: Option) -> Self { info!( "Initializing BootstrapManager with mode {:?} and tenant {:?}", install_mode, tenant ); + + if !Self::is_postgres_running() { + warn!("PostgreSQL server is not running. Attempting to start 'tables' component..."); + let pm = PackageManager::new(install_mode.clone(), tenant.clone()) + .expect("Failed to initialize PackageManager"); + if let Err(e) = pm.start("tables") { + error!("Failed to start PostgreSQL component automatically: {}", e); + panic!("Database not available and auto-start failed."); + } else { + info!("PostgreSQL component started successfully."); + } + } + let config = AppConfig::from_env().expect("Failed to load config from env"); let s3_client = futures::executor::block_on(Self::create_s3_operator(&config)); Self { diff --git a/src/session/mod.rs b/src/session/mod.rs index 93d707963..756d1c811 100644 --- a/src/session/mod.rs +++ b/src/session/mod.rs @@ -174,7 +174,7 @@ impl SessionManager { Ok(inserted) } - pub fn clear_messages(&mut self, session_id: Uuid) -> Result<(), Box> { + pub fn clear_messages(&mut self, _session_id: Uuid) -> Result<(), Box> { use crate::shared::models::message_history::dsl::*; diesel::delete(message_history.filter(session_id.eq(session_id))) diff --git a/src/shared/models.rs b/src/shared/models.rs index 25d151b7b..00052bd76 100644 --- a/src/shared/models.rs +++ b/src/shared/models.rs @@ -13,7 +13,7 @@ pub enum TriggerKind { } impl TriggerKind { - pub fn from_i32(value: i32) -> Option { + pub fn _from_i32(value: i32) -> Option { match value { 0 => Some(Self::Scheduled), 1 => Some(Self::TableUpdate), diff --git a/src/ui/stream.rs b/src/ui/stream.rs new file mode 100644 index 000000000..d61ec11ac --- /dev/null +++ b/src/ui/stream.rs @@ -0,0 +1,26 @@ +use ratatui::{ + style::{Color, Style}, + widgets::{Block, Borders, Gauge}, +}; + +pub struct StreamProgress { + pub progress: f64, + pub status: String, +} + +pub fn render_progress_bar(progress: &StreamProgress) -> Gauge { + let color = if progress.progress >= 1.0 { + Color::Green + } else { + Color::Blue + }; + + Gauge::default() + .block( + Block::default() + .title(format!("Stream Progress: {}", progress.status)) + .borders(Borders::ALL), + ) + .gauge_style(Style::default().fg(color)) + .percent((progress.progress * 100.0) as u16) +}