-- 2026-05-02: compteur visiteurs live / journalier / total
-- Tables first-party pour mesurer anonymement les visites après consentement audience.

CREATE TABLE IF NOT EXISTS visit_counter_sessions (
    visit_token CHAR(48) NOT NULL,
    first_seen_at DATETIME NOT NULL,
    last_seen_at DATETIME NOT NULL,
    created_at DATETIME NOT NULL,
    updated_at DATETIME NOT NULL,
    PRIMARY KEY (visit_token),
    KEY idx_last_seen_at (last_seen_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS visit_counter_daily (
    visit_token CHAR(48) NOT NULL,
    visit_date DATE NOT NULL,
    created_at DATETIME NOT NULL,
    PRIMARY KEY (visit_token, visit_date),
    KEY idx_visit_date (visit_date)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS visit_counter_meta (
    meta_key VARCHAR(64) NOT NULL,
    meta_value BIGINT UNSIGNED NOT NULL DEFAULT 0,
    updated_at DATETIME NOT NULL,
    PRIMARY KEY (meta_key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
