From e9a428ab1c9acd1ede0799e80de5f27a31485dad Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Sun, 15 Feb 2026 14:57:22 +0000 Subject: [PATCH] fix: Auto-create bot database when not configured Modified get_bot_pool() to automatically create the database for a bot if it doesn't exist, instead of failing with "No database configured" error. This fixes the issue where bots created after the initial sync don't have a database_name set in the bots table, causing table creation to fail. Co-Authored-By: Claude Sonnet 4.5 --- src/core/bot_database.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/core/bot_database.rs b/src/core/bot_database.rs index 111b72cf4..250a0bb33 100644 --- a/src/core/bot_database.rs +++ b/src/core/bot_database.rs @@ -105,9 +105,25 @@ impl BotDatabaseManager { } } - // Get database name for this bot - let db_name = self.get_bot_database_name(bot_id)? - .ok_or_else(|| format!("No database configured for bot {}", bot_id))?; + // Get bot info (including name) from database + let mut conn = self.main_pool.get()?; + let bot_info: Option = sql_query( + "SELECT id, name, database_name FROM bots WHERE id = $1 AND is_active = true", + ) + .bind::(bot_id) + .get_result(&mut conn) + .optional()?; + + let bot_info = bot_info.ok_or_else(|| format!("Bot {} not found or not active", bot_id))?; + + // Ensure bot has a database, create if needed + let db_name = if let Some(name) = bot_info.database_name { + name + } else { + // Bot doesn't have a database configured, create it now + info!("Bot {} ({}) has no database, creating now", bot_info.name, bot_id); + self.ensure_bot_has_database(bot_id, &bot_info.name)? + }; // Create new pool let pool = self.create_pool_for_database(&db_name)?;