Files
omnisupport-ai/backend/schema.sql
2026-02-17 10:40:49 +01:00

151 lines
7.6 KiB
SQL

-- Disabilita i controlli delle chiavi esterne per evitare errori durante la creazione/eliminazione
SET FOREIGN_KEY_CHECKS = 0;
-- 1. TABELLA QUEUES (Code di smistamento)
DROP TABLE IF EXISTS queues;
CREATE TABLE queues (
id VARCHAR(36) PRIMARY KEY,
name VARCHAR(50) NOT NULL UNIQUE,
description TEXT
);
INSERT INTO queues (id, name, description) VALUES
('q1', 'General', 'Richieste generiche e informazioni'),
('q2', 'Tech Support', 'Problemi tecnici hardware e software'),
('q3', 'Billing', 'Fatturazione, pagamenti e rimborsi');
-- 2. TABELLA AGENTS (Agenti, Supervisor, Superadmin)
DROP TABLE IF EXISTS agents;
CREATE TABLE agents (
id VARCHAR(36) PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
role ENUM('superadmin', 'supervisor', 'agent') DEFAULT 'agent',
avatar TEXT,
avatar_config JSON,
queues JSON, -- Array di stringhe (nomi delle code)
skills JSON, -- Array di stringhe
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Inserimento Superadmin Obbligatorio e Agenti Mock
INSERT INTO agents (id, name, email, password, role, avatar, avatar_config, queues, skills) VALUES
('a0', 'Super Admin', 'fcarra79@gmail.com', 'Mr10921.', 'superadmin', 'https://ui-avatars.com/api/?name=Super+Admin&background=0D8ABC&color=fff', '{"x": 50, "y": 50, "scale": 1}', '["General", "Tech Support", "Billing"]', '["All"]'),
('a1', 'Mario Rossi', 'mario@omni.ai', 'admin', 'agent', 'https://picsum.photos/id/1005/200/200', '{"x": 50, "y": 50, "scale": 1}', '["Tech Support", "General"]', '["Technical", "Linux"]'),
('a2', 'Giulia Bianchi', 'giulia@omni.ai', 'admin', 'supervisor', 'https://picsum.photos/id/1011/200/200', '{"x": 50, "y": 50, "scale": 1}', '["Billing"]', '["Billing", "Refunds"]');
-- 3. TABELLA CLIENT_USERS (Utenti finali)
DROP TABLE IF EXISTS client_users;
CREATE TABLE client_users (
id VARCHAR(36) PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
company VARCHAR(255),
status ENUM('active', 'inactive') DEFAULT 'active',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO client_users (id, name, email, password, company, status) VALUES
('u1', 'Luca Verdi', 'luca@client.com', 'user', 'Acme Corp', 'active'),
('u2', 'Anna Neri', 'anna@client.com', 'user', 'Globex', 'active'),
('u3', 'Giorgio Gialli', 'giorgio.g@example.com', 'user', NULL, 'inactive');
-- 4. TABELLA TICKETS
DROP TABLE IF EXISTS tickets;
CREATE TABLE tickets (
id VARCHAR(36) PRIMARY KEY,
subject VARCHAR(255) NOT NULL,
description TEXT,
status ENUM('APERTO', 'IN LAVORAZIONE', 'RISOLTO', 'CHIUSO') DEFAULT 'APERTO',
priority ENUM('Bassa', 'Media', 'Alta', 'Critica') DEFAULT 'Media',
customer_name VARCHAR(255),
assigned_agent_id VARCHAR(36),
queue VARCHAR(50),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
attachments JSON DEFAULT NULL, -- Array di oggetti Attachment
FOREIGN KEY (assigned_agent_id) REFERENCES agents(id) ON DELETE SET NULL
);
INSERT INTO tickets (id, subject, description, status, priority, customer_name, assigned_agent_id, queue, created_at) VALUES
('T-1001', 'Problema connessione VPN', 'Non riesco a connettermi alla VPN aziendale da casa.', 'APERTO', 'Alta', 'Luca Verdi', NULL, 'Tech Support', '2023-12-01 09:00:00'),
('T-1002', 'Errore Fattura Dicembre', 'La fattura riporta un importo errato rispetto al contratto.', 'RISOLTO', 'Media', 'Anna Neri', 'a2', 'Billing', '2023-11-28 14:30:00'),
('T-1003', 'Come configurare 2FA', 'Vorrei attivare la doppia autenticazione ma non trovo l''opzione.', 'RISOLTO', 'Bassa', 'Giorgio Gialli', 'a1', 'Tech Support', '2023-11-25 10:00:00');
-- 5. TABELLA TICKET_MESSAGES (Messaggi della chat del ticket)
DROP TABLE IF EXISTS ticket_messages;
CREATE TABLE ticket_messages (
id VARCHAR(36) PRIMARY KEY,
ticket_id VARCHAR(36) NOT NULL,
role ENUM('user', 'assistant', 'system') NOT NULL,
content TEXT,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (ticket_id) REFERENCES tickets(id) ON DELETE CASCADE
);
INSERT INTO ticket_messages (id, ticket_id, role, content, timestamp) VALUES
('m1', 'T-1002', 'user', 'La fattura è di 50€ invece di 30€.', '2023-11-28 14:30:00'),
('m2', 'T-1002', 'assistant', 'Ciao Anna, ho verificato. C''era un errore nel calcolo dell''IVA. Ho emesso una nota di credito.', '2023-11-28 15:00:00'),
('m3', 'T-1002', 'user', 'Grazie mille, risolto.', '2023-11-28 15:10:00'),
('m4', 'T-1003', 'user', 'Dove trovo il 2FA?', '2023-11-25 10:00:00'),
('m5', 'T-1003', 'assistant', 'Ciao Giorgio. Devi scaricare Google Authenticator. Poi vai nel tuo profilo, clicca su "Sicurezza Avanzata" e scansiona il QR code.', '2023-11-25 10:15:00');
-- 6. TABELLA KB_ARTICLES (Knowledge Base)
DROP TABLE IF EXISTS kb_articles;
CREATE TABLE kb_articles (
id VARCHAR(36) PRIMARY KEY,
title VARCHAR(255) NOT NULL,
content TEXT, -- Markdown o contenuto estratto
category VARCHAR(100),
type ENUM('article', 'url') DEFAULT 'article',
url TEXT,
source ENUM('manual', 'ai') DEFAULT 'manual',
last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
INSERT INTO kb_articles (id, title, content, category, type, url, source, last_updated) VALUES
('kb1', 'Come reimpostare la password', 'Per reimpostare la password, vai su Impostazioni > Sicurezza e clicca su "Cambia Password". Ti verrà inviata una mail di conferma.', 'Account', 'article', NULL, 'manual', '2023-10-15 10:00:00'),
('kb2', 'Configurazione Email su Outlook', '1. Apri Outlook. 2. File > Aggiungi Account. 3. Inserisci la tua mail. 4. Seleziona IMAP. Server in entrata: imap.example.com porta 993.', 'Tecnico', 'article', NULL, 'manual', '2023-11-02 11:30:00'),
('kb3', 'Documentazione API Ufficiale', 'Riferimento esterno alla documentazione.', 'Sviluppo', 'url', 'https://example.com/api-docs', 'manual', '2023-09-20 09:00:00');
-- 7. TABELLA SURVEY_RESULTS (Feedback e Sondaggi)
DROP TABLE IF EXISTS survey_results;
CREATE TABLE survey_results (
id VARCHAR(36) PRIMARY KEY,
rating INT NOT NULL, -- 1-5
comment TEXT,
source ENUM('chat', 'ticket') NOT NULL,
reference_id VARCHAR(36), -- Ticket ID se source è ticket
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO survey_results (id, rating, comment, source, reference_id, timestamp) VALUES
('s1', 5, 'Ottimo servizio, molto veloce!', 'ticket', 'T-1002', '2023-11-28 16:00:00'),
('s2', 4, 'Buono, ma l''attesa è stata lunghetta.', 'chat', NULL, '2023-12-02 10:30:00'),
('s3', 5, 'AI molto intelligente, ha risolto subito.', 'chat', NULL, '2023-12-03 09:15:00'),
('s4', 2, 'Non ha capito la mia domanda.', 'chat', NULL, '2023-12-01 14:20:00');
-- 8. TABELLA SETTINGS (Configurazione Globale)
DROP TABLE IF EXISTS settings;
CREATE TABLE settings (
id INT PRIMARY KEY DEFAULT 1,
branding JSON,
smtp JSON,
email_templates JSON,
features JSON,
ai_config JSON
);
INSERT INTO settings (id, branding, smtp, email_templates, features, ai_config) VALUES (
1,
'{"appName": "OmniSupport AI", "primaryColor": "#0284c7", "logoUrl": "https://via.placeholder.com/150"}',
'{"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}'
);
SET FOREIGN_KEY_CHECKS = 1;