From 5669515c682156a8167743eb8fb453395f15a68f Mon Sep 17 00:00:00 2001 From: "Rodrigo Rodriguez (Pragmatismo)" Date: Tue, 9 Dec 2025 07:49:01 -0300 Subject: [PATCH] fix(bootstrap): Run migrations with direct password before Vault is set up The bootstrap order is vault -> tables -> directory. When tables component was processed, it tried to call establish_pg_connection() which requires Vault, but Vault setup only happens when processing the vault component (which is earlier in the loop but the if-block for tables runs for the tables component, not vault). Fix: Run migrations directly with the generated password during the tables component setup, before Vault is configured. This avoids the dependency on Vault being set up. --- src/core/bootstrap/mod.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/core/bootstrap/mod.rs b/src/core/bootstrap/mod.rs index 1e7de6336..344d5ae58 100644 --- a/src/core/bootstrap/mod.rs +++ b/src/core/bootstrap/mod.rs @@ -5,7 +5,7 @@ use crate::shared::utils::{establish_pg_connection, init_secrets_manager}; use anyhow::Result; use aws_config::BehaviorVersion; use aws_sdk_s3::Client; -use diesel::RunQueryDsl; +use diesel::{Connection, RunQueryDsl}; use log::debug; use log::{error, info, trace, warn}; use rand::distr::Alphanumeric; @@ -574,6 +574,23 @@ impl BootstrapManager { } } + // Run migrations using direct connection (Vault not set up yet) + info!("🔄 Running database migrations..."); + let database_url = + format!("postgres://gbuser:{}@localhost:5432/botserver", db_password); + match diesel::PgConnection::establish(&database_url) { + Ok(mut conn) => { + if let Err(e) = self.apply_migrations(&mut conn) { + error!("Failed to apply migrations: {}", e); + } else { + info!("✓ Database migrations applied"); + } + } + Err(e) => { + error!("Failed to connect to database for migrations: {}", e); + } + } + info!("🔧 Creating Directory configuration files..."); if let Err(e) = self.configure_services_in_directory(&db_password).await { error!("Failed to create Directory config files: {}", e); @@ -636,11 +653,6 @@ impl BootstrapManager { } } - if component == "tables" { - let mut conn = establish_pg_connection().unwrap(); - self.apply_migrations(&mut conn)?; - } - if component == "email" { info!("🔧 Auto-configuring Email (Stalwart)..."); if let Err(e) = self.setup_email().await {