-- Adds visitor/request logging, read by the new admin-only log_dashboard.php.
-- Run once via phpMyAdmin.

CREATE TABLE IF NOT EXISTS visitor_log (
    id          INT UNSIGNED  NOT NULL AUTO_INCREMENT,
    ip          VARCHAR(45)   NOT NULL,
    country     VARCHAR(64)   NULL,
    region      VARCHAR(64)   NULL,
    city        VARCHAR(64)   NULL,
    latitude    DECIMAL(9,6)  NULL,
    longitude   DECIMAL(9,6)  NULL,
    isp         VARCHAR(128)  NULL,
    page        VARCHAR(512)  NOT NULL,
    referrer    VARCHAR(512)  NULL,
    user_agent  VARCHAR(512)  NULL,
    browser     VARCHAR(64)   NULL,
    os          VARCHAR(64)   NULL,
    device      VARCHAR(32)   NULL,
    language    VARCHAR(32)   NULL,
    visited_at  DATETIME      NOT NULL,
    PRIMARY KEY (id),
    KEY idx_visitor_log_ip (ip),
    KEY idx_visitor_log_country (country),
    KEY idx_visitor_log_visited_at (visited_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
