Update db.js
This commit is contained in:
@@ -64,7 +64,20 @@ export const initDb = async () => {
|
|||||||
|
|
||||||
// Scenario 1: DB completely initialized
|
// Scenario 1: DB completely initialized
|
||||||
if (agentsExist.length > 0 && settingsExist.length > 0) {
|
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;
|
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"}',
|
'{"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}]',
|
'[{"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}',
|
'{"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);
|
await pool.query(createSettingsSql);
|
||||||
|
|||||||
Reference in New Issue
Block a user