

-- Create API usage tracking table
CREATE TABLE IF NOT EXISTS api_usage_log (
    id INT AUTO_INCREMENT PRIMARY KEY,
    token_id VARCHAR(64) NOT NULL,
    user_id INT NOT NULL,
    endpoint VARCHAR(255),
    method VARCHAR(10),
    request_url TEXT,
    ip_address VARCHAR(45),
    user_agent TEXT,
    response_status INT,
    request_size_bytes INT DEFAULT 0,
    response_size_bytes INT DEFAULT 0,
    processing_time_ms INT DEFAULT 0,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_token_id (token_id),
    INDEX idx_user_id (user_id),
    INDEX idx_created_at (created_at),
    INDEX idx_status (response_status),
    FOREIGN KEY (token_id) REFERENCES user_api_tokens(token_id) ON DELETE CASCADE
);
