From c39984debec234159c810c9fb21448cdccf7377c Mon Sep 17 00:00:00 2001 From: fcarraUniSa Date: Tue, 17 Feb 2026 11:26:24 +0100 Subject: [PATCH] Update db.js --- backend/db.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/backend/db.js b/backend/db.js index c028bd4..fbc8aa6 100644 --- a/backend/db.js +++ b/backend/db.js @@ -64,7 +64,20 @@ export const initDb = async () => { // Scenario 1: DB completely initialized if (agentsExist.length > 0 && settingsExist.length > 0) { - console.log('ℹ️ Database tables already exist. Skipping initialization.'); + console.log('ℹ️ Database tables already exist. Checking for migrations...'); + + // MIGRATION: Add 'visibility' to kb_articles if not exists + try { + await pool.query("ALTER TABLE kb_articles ADD COLUMN visibility ENUM('public', 'internal') DEFAULT 'public'"); + console.log("✅ Added visibility column to kb_articles"); + } catch (e) { /* Column likely exists */ } + + // MIGRATION: Add 'has_been_analyzed' to tickets if not exists + try { + await pool.query("ALTER TABLE tickets ADD COLUMN has_been_analyzed BOOLEAN DEFAULT FALSE"); + console.log("✅ Added has_been_analyzed column to tickets"); + } catch (e) { /* Column likely exists */ } + return; } @@ -86,7 +99,7 @@ export const initDb = async () => { '{"host": "smtp.example.com", "port": 587, "user": "notifications@omnisupport.ai", "pass": "password", "secure": true, "fromEmail": "noreply@omnisupport.ai"}', '[{"id": "t1", "name": "Conferma Apertura Ticket", "trigger": "ticket_created", "audience": "client", "subject": "Ticket #{ticket_id} Creato", "body": "Grazie per averci contattato.", "isActive": true}]', '{"kbEnabled": true, "maxKbArticles": 50, "maxSupervisors": 2, "aiKnowledgeAgentEnabled": true, "maxAiGeneratedArticles": 10, "maxAgents": 10}', - '{"provider": "gemini", "apiKey": "", "model": "gemini-3-flash-preview", "isActive": true}' + '{"provider": "gemini", "apiKey": "", "model": "gemini-3-flash-preview", "isActive": true, "agentName": "OmniSupport AI", "customPrompt": ""}' ); `; await pool.query(createSettingsSql);