CREATE TABLE IF NOT EXISTS sessions (
    id              INT AUTO_INCREMENT PRIMARY KEY,
    session_id      VARCHAR(64) NOT NULL,
    first_page      VARCHAR(2048) NOT NULL,
    last_page       VARCHAR(2048) NOT NULL,
    page_count      INT UNSIGNED NOT NULL DEFAULT 1,
    start_time      DATETIME NOT NULL,
    last_activity   DATETIME NOT NULL,
    duration_seconds INT UNSIGNED NOT NULL DEFAULT 0,
    referrer        VARCHAR(2048),
    user_agent      VARCHAR(512),
    created_at      TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

    INDEX idx_session_id (session_id),
    INDEX idx_start_time (start_time),
    INDEX idx_last_activity (last_activity)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
