-- Migration à exécuter UNE FOIS si tu as déjà installé la version
-- précédente (multi-clients sans Admin+ ni journal).
-- Si tu pars d'une base neuve, utilise directement schema.sql.

ALTER TABLE admin_users MODIFY client_id INT DEFAULT NULL;
ALTER TABLE admin_users ADD COLUMN is_superadmin TINYINT(1) NOT NULL DEFAULT 0 AFTER client_id;

CREATE TABLE IF NOT EXISTS video_plays (
    id INT AUTO_INCREMENT PRIMARY KEY,
    client_id INT NOT NULL,
    video_id INT DEFAULT NULL,
    video_name VARCHAR(255) NOT NULL,
    played_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (client_id) REFERENCES clients(id) ON DELETE CASCADE,
    FOREIGN KEY (video_id) REFERENCES videos(id) ON DELETE SET NULL,
    INDEX idx_client_day (client_id, played_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
