CREATE TABLE IF NOT EXISTS radio_play_history (
    id int(11) NOT NULL AUTO_INCREMENT,
    radio_id int(11) NOT NULL,
    media_id int(11) NULL,
    playlist_id int(11) NULL,
    playlist_item_id int(11) NULL,
    title varchar(255) NOT NULL,
    artist varchar(255) NOT NULL,
    raw_title varchar(255) NOT NULL,
    source varchar(40) NOT NULL DEFAULT 'icecast',
    content_type varchar(40) NOT NULL DEFAULT 'music',
    cover_path varchar(255) NULL,
    started_at datetime NOT NULL,
    ended_at datetime NULL,
    duration_seconds int(11) NULL,
    created_at datetime NOT NULL,
    updated_at datetime NOT NULL,
    PRIMARY KEY (id),
    KEY idx_radio_play_history_radio_started (radio_id, started_at),
    KEY idx_radio_play_history_radio_open (radio_id, ended_at),
    KEY idx_radio_play_history_media (media_id),
    KEY idx_radio_play_history_playlist (playlist_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
