/* ======================================================== TABLE : conversations ======================================================== Cette table représente une discussion entre : - un citoyen - un candidat 👉 1 ligne = 1 chat ======================================================== */ CREATE TABLE conversations ( id INT AUTO_INCREMENT PRIMARY KEY, citoyen_id INT NOT NULL, candidat_id INT NOT NULL, date_creation DATETIME DEFAULT CURRENT_TIMESTAMP, INDEX(citoyen_id), INDEX(candidat_id) ); /* ======================================================== TABLE : messages ======================================================== Chaque message appartient à une conversation. 👉 stocke tout le chat ======================================================== */ CREATE TABLE messages ( id INT AUTO_INCREMENT PRIMARY KEY, conversation_id INT NOT NULL, expediteur_type ENUM('citoyen','candidat') NOT NULL, expediteur_id INT NOT NULL, message TEXT NOT NULL, ip VARCHAR(100), user_agent TEXT, date_envoi DATETIME DEFAULT CURRENT_TIMESTAMP, lu TINYINT(1) DEFAULT 0, INDEX(conversation_id), INDEX(expediteur_id) );