Update db.js

This commit is contained in:
fcarraUniSa
2026-02-17 11:26:24 +01:00
committed by GitHub
parent 170c3fa76a
commit c39984debe

View File

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