Remove tables install from bootstrap

The tables component is now installed by default. The install command no
longer installs it as part of the bootstrap process.
This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2025-10-20 07:34:06 -03:00
parent f8d4e8925f
commit ed93f70f94
4 changed files with 71 additions and 28 deletions

View file

@ -1,2 +1,2 @@
clear && \
RUST_LOG=trace cargo run install tables
RUST_LOG=trace cargo run

View file

@ -1,7 +1,7 @@
use crate::config::AppConfig;
use crate::package_manager::{InstallMode, PackageManager};
use anyhow::Result;
use log::{debug, trace, warn};
use log::{trace, warn};
use rand::distr::Alphanumeric;
use rand::rngs::ThreadRng;
use rand::Rng;
@ -14,7 +14,11 @@ pub struct BootstrapManager {
impl BootstrapManager {
pub fn new(install_mode: InstallMode, tenant: Option<String>) -> Self {
trace!("Initializing BootstrapManager with mode {:?} and tenant {:?}", install_mode, tenant);
trace!(
"Initializing BootstrapManager with mode {:?} and tenant {:?}",
install_mode,
tenant
);
Self {
install_mode,
tenant,
@ -24,9 +28,26 @@ impl BootstrapManager {
pub fn start_all(&mut self) -> Result<()> {
let pm = PackageManager::new(self.install_mode.clone(), self.tenant.clone())?;
let components = vec![
"tables", "cache", "drive", "llm", "email", "proxy", "directory",
"alm", "alm_ci", "dns", "webmail", "meeting", "table_editor",
"doc_editor", "desktop", "devtools", "bot", "system", "vector_db", "host"
"tables",
"cache",
"drive",
"llm",
"email",
"proxy",
"directory",
"alm",
"alm_ci",
"dns",
"webmail",
"meeting",
"table_editor",
"doc_editor",
"desktop",
"devtools",
"bot",
"system",
"vector_db",
"host",
];
for component in components {
@ -42,8 +63,8 @@ impl BootstrapManager {
pub fn bootstrap(&mut self) -> Result<AppConfig> {
let pm = PackageManager::new(self.install_mode.clone(), self.tenant.clone())?;
let required_components = vec!["tables", "cache", "drive", "llm"];
let required_components = vec!["tables"]; // , "cache", "drive", "llm"];
for component in required_components {
if !pm.is_installed(component) {
trace!("Installing required component: {}", component);
@ -55,7 +76,9 @@ impl BootstrapManager {
}
}
let config = match diesel::Connection::establish("postgres://botserver:botserver@localhost:5432/botserver") {
let config = match diesel::Connection::establish(
"postgres://botserver:botserver@localhost:5432/botserver",
) {
Ok(mut conn) => {
self.setup_secure_credentials(&mut conn)?;
AppConfig::from_database(&mut conn)
@ -74,16 +97,17 @@ impl BootstrapManager {
use diesel::prelude::*;
use uuid::Uuid;
let farm_password = std::env::var("FARM_PASSWORD").unwrap_or_else(|_| self.generate_secure_password(32));
let farm_password =
std::env::var("FARM_PASSWORD").unwrap_or_else(|_| self.generate_secure_password(32));
let db_password = self.generate_secure_password(16);
let encrypted_db_password = self.encrypt_password(&db_password, &farm_password);
let env_contents = format!(
"FARM_PASSWORD={}\nDATABASE_URL=postgres://gbuser:{}@localhost:5432/botserver",
farm_password, db_password
);
std::fs::write(".env", env_contents)
.map_err(|e| anyhow::anyhow!("Failed to write .env file: {}", e))?;
@ -99,7 +123,7 @@ impl BootstrapManager {
}
fn generate_secure_password(&self, length: usize) -> String {
let mut rng: ThreadRng = rand::thread_rng();
let rng: ThreadRng = rand::rng();
rng.sample_iter(&Alphanumeric)
.take(length)
.map(char::from)

View file

@ -648,6 +648,7 @@ impl PackageManager {
);
Ok(std::process::Command::new("sh")
.current_dir(&bin_path)
.arg("-c")
.arg(&rendered_cmd)
.spawn()?)
@ -657,7 +658,7 @@ impl PackageManager {
}
fn generate_secure_password(&self, length: usize) -> String {
let mut rng: ThreadRng = rand::thread_rng();
let rng: ThreadRng = rand::rng();
rng.sample_iter(&Alphanumeric)
.take(length)
.map(char::from)

View file

@ -1,4 +1,8 @@
use log::{debug, trace};
use crate::config::AIConfig;
use futures_util::StreamExt;
use indicatif::{ProgressBar, ProgressStyle};
use log::trace;
use reqwest::Client;
use rhai::{Array, Dynamic};
use serde_json::Value;
use smartstring::SmartString;
@ -7,14 +11,13 @@ use std::fs::File;
use std::io::BufReader;
use std::path::Path;
use tokio::fs::File as TokioFile;
use zip::ZipArchive;
use crate::config::AIConfig;
use reqwest::Client;
use tokio::io::AsyncWriteExt;
use indicatif::{ProgressBar, ProgressStyle};
use futures_util::StreamExt;
use zip::ZipArchive;
pub fn extract_zip_recursive(zip_path: &Path, destination_path: &Path) -> Result<(), Box<dyn std::error::Error>> {
pub fn extract_zip_recursive(
zip_path: &Path,
destination_path: &Path,
) -> Result<(), Box<dyn std::error::Error>> {
let file = File::open(zip_path)?;
let buf_reader = BufReader::new(file);
let mut archive = ZipArchive::new(buf_reader)?;
@ -75,14 +78,17 @@ pub fn to_array(value: Dynamic) -> Array {
}
}
pub async fn download_file(url: &str, output_path: &str) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
pub async fn download_file(
url: &str,
output_path: &str,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let url = url.to_string();
let output_path = output_path.to_string();
let download_handle = tokio::spawn(async move {
let client = Client::new();
let response = client.get(&url).send().await?;
if response.status().is_success() {
let total_size = response.content_length().unwrap_or(0);
let pb = ProgressBar::new(total_size);
@ -123,14 +129,20 @@ pub fn parse_filter(filter_str: &str) -> Result<(String, Vec<String>), Box<dyn E
let column = parts[0].trim();
let value = parts[1].trim();
if !column.chars().all(|c| c.is_ascii_alphanumeric() || c == '_') {
if !column
.chars()
.all(|c| c.is_ascii_alphanumeric() || c == '_')
{
return Err("Invalid column name in filter".into());
}
Ok((format!("{} = $1", column), vec![value.to_string()]))
}
pub fn parse_filter_with_offset(filter_str: &str, offset: usize) -> Result<(String, Vec<String>), Box<dyn Error>> {
pub fn parse_filter_with_offset(
filter_str: &str,
offset: usize,
) -> Result<(String, Vec<String>), Box<dyn Error>> {
let mut clauses = Vec::new();
let mut params = Vec::new();
@ -143,7 +155,10 @@ pub fn parse_filter_with_offset(filter_str: &str, offset: usize) -> Result<(Stri
let column = parts[0].trim();
let value = parts[1].trim();
if !column.chars().all(|c| c.is_ascii_alphanumeric() || c == '_') {
if !column
.chars()
.all(|c| c.is_ascii_alphanumeric() || c == '_')
{
return Err("Invalid column name".into());
}
@ -154,6 +169,9 @@ pub fn parse_filter_with_offset(filter_str: &str, offset: usize) -> Result<(Stri
Ok((clauses.join(" AND "), params))
}
pub async fn call_llm(prompt: &str, _ai_config: &AIConfig) -> Result<String, Box<dyn std::error::Error + Send + Sync>> {
pub async fn call_llm(
prompt: &str,
_ai_config: &AIConfig,
) -> Result<String, Box<dyn std::error::Error + Send + Sync>> {
Ok(format!("Generated response for: {}", prompt))
}