

-- Table des rêves
CREATE TABLE IF NOT EXISTS `dream_reves` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `utilisateur_id` INT(11) NOT NULL,
    `date_time` DATETIME NOT NULL,
    `titre` VARCHAR(255) DEFAULT NULL,
    `histoire` TEXT NOT NULL,
    `emotions` VARCHAR(255) DEFAULT NULL,
    `symboles` VARCHAR(255) DEFAULT NULL,
    `interpretation` TEXT DEFAULT NULL,
    `action_priere` TEXT DEFAULT NULL,
    `suivi` TEXT DEFAULT NULL,
    `date_creation` DATETIME NOT NULL,
    `date_modification` DATETIME DEFAULT NULL,
    PRIMARY KEY (`id`),
    FOREIGN KEY (`utilisateur_id`) REFERENCES `dream_utilisateurs`(`id`) ON DELETE CASCADE,
    INDEX `idx_utilisateur` (`utilisateur_id`),
    INDEX `idx_date` (`date_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table des sessions
CREATE TABLE IF NOT EXISTS `dream_sessions` (
    `id` VARCHAR(128) NOT NULL,
    `utilisateur_id` INT(11) NOT NULL,
    `ip_address` VARCHAR(45) NOT NULL,
    `user_agent` TEXT,
    `payload` TEXT NOT NULL,
    `last_activity` INT(11) NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `idx_last_activity` (`last_activity`),
    INDEX `idx_utilisateur` (`utilisateur_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table des logs admin
CREATE TABLE IF NOT EXISTS `dream_logs_admin` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `admin_id` INT(11) NOT NULL,
    `action` VARCHAR(255) NOT NULL,
    `details` TEXT,
    `ip_address` VARCHAR(45) NOT NULL,
    `date_action` DATETIME NOT NULL,
    PRIMARY KEY (`id`),
    FOREIGN KEY (`admin_id`) REFERENCES `dream_utilisateurs`(`id`) ON DELETE CASCADE,
    INDEX `idx_admin` (`admin_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;