-- ===================================================================== -- 050 — Inventario a DUE voci + sottoclassi configurabili (Epic C / C4) -- ===================================================================== -- Simon C4: nell'inventario DUE sole voci principali (ID.AM-01 Hardware, -- ID.AM-02 Software/Servizi/Sistemi); il dettaglio diventa SOTTOCLASSE -- (config: default di sistema + create dall'utente). Riconduzione concordata: -- hardware/network/facility -> ID.AM-01 ; software/service/data -> ID.AM-02 ; -- personnel -> Organigramma (nessun asset personnel presente). -- -- Additivo: aggiunge cfg_inventory_voci, inventory_subclassi e -- assets.voce_code/subclass_id; NON tocca asset_type (resta come legacy per le -- viste secondarie). Migrazione dati inclusa (vedi runner). Reversibile. -- Runner-safe: solo CREATE/ALTER bare (no DELIMITER). -- ===================================================================== CREATE TABLE IF NOT EXISTS cfg_inventory_voci ( voce_code VARCHAR(16) NOT NULL, label VARCHAR(120) NOT NULL, descr TEXT NULL, ord INT NOT NULL, PRIMARY KEY (voce_code) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; CREATE TABLE IF NOT EXISTS inventory_subclassi ( id INT NOT NULL AUTO_INCREMENT, organization_id INT NULL, -- NULL = default di sistema; valorizzato = sottoclasse dell'org voce_code VARCHAR(16) NOT NULL, label VARCHAR(120) NOT NULL, ord INT NOT NULL DEFAULT 0, PRIMARY KEY (id), UNIQUE KEY uq_subclass (organization_id, voce_code, label), KEY idx_subclass_org (organization_id), KEY idx_subclass_voce (voce_code), CONSTRAINT fk_subclass_voce FOREIGN KEY (voce_code) REFERENCES cfg_inventory_voci (voce_code), CONSTRAINT fk_subclass_org FOREIGN KEY (organization_id) REFERENCES organizations (id) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; ALTER TABLE assets ADD COLUMN voce_code VARCHAR(16) NULL DEFAULT NULL; ALTER TABLE assets ADD COLUMN subclass_id INT NULL DEFAULT NULL; ALTER TABLE assets ADD CONSTRAINT fk_assets_subclass FOREIGN KEY (subclass_id) REFERENCES inventory_subclassi (id) ON DELETE SET NULL;