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.
This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2025-11-07 09:37:45 -03:00
parent 1a4b56e312
commit 3f187feccb
5 changed files with 54 additions and 5 deletions

View file

@ -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<MCPTool>,
pub openai_tool: Option<OpenAITool>,
pub _openai_tool: Option<OpenAITool>,
}

View file

@ -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<String>) -> 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 {

View file

@ -174,7 +174,7 @@ impl SessionManager {
Ok(inserted)
}
pub fn clear_messages(&mut self, session_id: Uuid) -> Result<(), Box<dyn Error + Send + Sync>> {
pub fn clear_messages(&mut self, _session_id: Uuid) -> Result<(), Box<dyn Error + Send + Sync>> {
use crate::shared::models::message_history::dsl::*;
diesel::delete(message_history.filter(session_id.eq(session_id)))

View file

@ -13,7 +13,7 @@ pub enum TriggerKind {
}
impl TriggerKind {
pub fn from_i32(value: i32) -> Option<Self> {
pub fn _from_i32(value: i32) -> Option<Self> {
match value {
0 => Some(Self::Scheduled),
1 => Some(Self::TableUpdate),

26
src/ui/stream.rs Normal file
View file

@ -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)
}