From eddc2fe79d5c726b0674664d8f05a56c08d9294f Mon Sep 17 00:00:00 2001 From: DevEnv nis2-agile Date: Mon, 9 Mar 2026 09:04:48 +0100 Subject: [PATCH] [FIX] reset-demo.sql: adatta a struttura reale DB (incident_timeline, capa_actions, email_log, users) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - incident_timeline: join su incidents (no organization_id diretto) - corrective_actions → capa_actions, non_conformity_id → ncr_id - email_log: filtra per recipient LIKE '%.demo%' (no organization_id) - users INSERT: first_name/last_name/status → full_name/is_active Co-Authored-By: Claude Sonnet 4.6 --- docs/sql/reset-demo.sql | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/docs/sql/reset-demo.sql b/docs/sql/reset-demo.sql index f76dff7..158055b 100644 --- a/docs/sql/reset-demo.sql +++ b/docs/sql/reset-demo.sql @@ -15,7 +15,8 @@ SET FOREIGN_KEY_CHECKS = 0; -- ── Dati operativi generati dalla simulazione ───────────────────────────── -- Notifiche incidenti / timeline -DELETE FROM incident_timeline WHERE organization_id > 4; +DELETE FROM incident_timeline + WHERE incident_id IN (SELECT id FROM incidents WHERE organization_id > 4); DELETE FROM incidents WHERE organization_id > 4; -- Rischi e trattamenti @@ -46,7 +47,7 @@ DELETE FROM compliance_controls WHERE organization_id > 4; DELETE FROM evidence_files WHERE organization_id > 4; -- Non conformità e CAPA -DELETE FROM corrective_actions WHERE non_conformity_id IN (SELECT id FROM non_conformities WHERE organization_id > 4); +DELETE FROM capa_actions WHERE ncr_id IN (SELECT id FROM non_conformities WHERE organization_id > 4); DELETE FROM non_conformities WHERE organization_id > 4; -- Whistleblowing @@ -71,8 +72,8 @@ DELETE FROM audit_violations WHERE organization_id > 4; -- AI interactions DELETE FROM ai_interactions WHERE organization_id > 4; --- Email log -DELETE FROM email_log WHERE organization_id > 4; +-- Email log (no organization_id — pulisce solo email con indirizzo demo) +DELETE FROM email_log WHERE recipient LIKE '%.demo%'; -- ── Membership utenti ───────────────────────────────────────────────────── @@ -98,15 +99,15 @@ DELETE rt FROM refresh_tokens rt JOIN users u ON rt.user_id = u.id WHERE u.email = 'cristiano.benassati@gmail.com'; -INSERT INTO users (email, password_hash, first_name, last_name, role, status) +INSERT INTO users (email, password_hash, full_name, role, is_active) VALUES ( 'cristiano.benassati@gmail.com', '$2y$12$H/AJ7SgBowihcOcpblQ7PeanmoTXzgruv3mRvC.vexoRodNa7rAUi', - 'Cristiano', 'Benassati', 'super_admin', 'active' + 'Cristiano Benassati', 'super_admin', 1 ) ON DUPLICATE KEY UPDATE role = 'super_admin', - status = 'active', + is_active = 1, password_hash = '$2y$12$H/AJ7SgBowihcOcpblQ7PeanmoTXzgruv3mRvC.vexoRodNa7rAUi'; -- ── Ripristino FK ─────────────────────────────────────────────────────────