-- Migration 001 : Schéma initial de ProxmoxPanel -- Crée toutes les tables de base nécessaires au CORE -- Paramètres globaux de l'application (clé/valeur) CREATE TABLE IF NOT EXISTS settings ( key TEXT PRIMARY KEY, value TEXT NOT NULL, encrypted INTEGER NOT NULL DEFAULT 0, updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ); -- Utilisateurs (créés automatiquement au premier login) CREATE TABLE IF NOT EXISTS users ( id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT NOT NULL UNIQUE, is_admin INTEGER NOT NULL DEFAULT 0, lang TEXT NOT NULL DEFAULT 'en', theme TEXT NOT NULL DEFAULT 'dark', sidebar_position TEXT NOT NULL DEFAULT 'left', created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, last_login_at DATETIME ); -- Sessions de refresh JWT (cookie httpOnly) CREATE TABLE IF NOT EXISTS refresh_tokens ( id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE, token_hash TEXT NOT NULL UNIQUE, expires_at DATETIME NOT NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ); -- Modules disponibles et leur état (actif/inactif) CREATE TABLE IF NOT EXISTS modules ( id TEXT PRIMARY KEY, name TEXT NOT NULL, description TEXT NOT NULL DEFAULT '', version TEXT NOT NULL DEFAULT '0.0.0', is_core INTEGER NOT NULL DEFAULT 0, is_enabled INTEGER NOT NULL DEFAULT 0, installed_at DATETIME, config TEXT NOT NULL DEFAULT '{}' ); -- Journal d'audit — toutes les actions sensibles CREATE TABLE IF NOT EXISTS audit_log ( id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER REFERENCES users(id) ON DELETE SET NULL, username TEXT, action TEXT NOT NULL, resource TEXT, details TEXT, ip TEXT, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ); -- Widgets du dashboard par utilisateur CREATE TABLE IF NOT EXISTS user_widgets ( id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE, widget_type TEXT NOT NULL, title TEXT NOT NULL, config TEXT NOT NULL DEFAULT '{}', position_x INTEGER NOT NULL DEFAULT 0, position_y INTEGER NOT NULL DEFAULT 0, width INTEGER NOT NULL DEFAULT 2, height INTEGER NOT NULL DEFAULT 2, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ); -- Historique des mises à jour de paquets CREATE TABLE IF NOT EXISTS update_history ( id INTEGER PRIMARY KEY AUTOINCREMENT, job_id TEXT NOT NULL UNIQUE, target TEXT NOT NULL, status TEXT NOT NULL DEFAULT 'pending', output TEXT NOT NULL DEFAULT '', started_by INTEGER REFERENCES users(id) ON DELETE SET NULL, started_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, finished_at DATETIME ); -- Version de schéma pour le système de migrations CREATE TABLE IF NOT EXISTS schema_version ( version INTEGER NOT NULL, applied_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ); INSERT INTO schema_version (version) VALUES (1); -- Insertion des modules CORE par défaut (non désinstallables) INSERT OR IGNORE INTO modules (id, name, description, version, is_core, is_enabled) VALUES ('dashboard', 'Dashboard', 'Tableau de bord avec widgets configurables', '1.0.0', 1, 1), ('proxmox', 'Proxmox', 'Gestion des LXC et VM Proxmox', '1.0.0', 1, 1), ('updates', 'Mises à jour', 'Mises à jour de paquets apt avec streaming', '1.0.0', 1, 1), ('terminal', 'Terminal', 'Terminal SSH interactif', '1.0.0', 0, 0), ('settings', 'Paramètres', 'Configuration de l''application', '1.0.0', 1, 1);