CREATE TABLE IF NOT EXISTS auth_login_attempts (
    id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    throttle_key CHAR(64) NOT NULL,
    email VARCHAR(255) NULL,
    ip_address VARCHAR(45) NULL,
    user_agent VARCHAR(255) NULL,
    failed_count INT UNSIGNED NOT NULL DEFAULT 0,
    first_failed_at TIMESTAMP NULL,
    last_failed_at TIMESTAMP NULL,
    locked_until TIMESTAMP NULL,
    created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (id),
    UNIQUE KEY uq_auth_login_attempts_key (throttle_key),
    KEY idx_auth_login_attempts_locked_until (locked_until),
    KEY idx_auth_login_attempts_email (email)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
