-- Durable per-IP request counters backing the RateLimit *detection module*
-- (requests per second/minute/hour). The HTTP throttle middleware uses the
-- cache layer; this table gives the scoring engine a persistent view.
CREATE TABLE IF NOT EXISTS `rate_limits` (
    `id`           BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    `rl_key`       VARCHAR(191)    NOT NULL,   -- e.g. ip:1.2.3.4:minute:202601011200
    `hits`         INT UNSIGNED    NOT NULL DEFAULT 0,
    `window_start` DATETIME        NOT NULL,
    `expires_at`   DATETIME        NOT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `uq_rl_key` (`rl_key`),
    KEY `idx_rl_expires` (`expires_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
