-- Migration: Add proxy_ip tracking to worker_tasks
-- Purpose: Prevent same IP from hitting multiple stores on same platform simultaneously
--
-- Anti-detection measure: Dutchie/Jane may flag if same IP makes requests
-- for multiple different stores. This column lets us track and prevent that.

-- Add proxy_ip column to track which proxy IP is being used for each task
ALTER TABLE worker_tasks ADD COLUMN IF NOT EXISTS proxy_ip VARCHAR(45);

-- Index for quick lookup of active tasks by proxy IP
-- Used to check: "Is this IP already hitting another store?"
CREATE INDEX IF NOT EXISTS idx_worker_tasks_proxy_ip_active
ON worker_tasks (proxy_ip, platform)
WHERE status IN ('claimed', 'running') AND proxy_ip IS NOT NULL;

-- Comment
COMMENT ON COLUMN worker_tasks.proxy_ip IS 'Proxy IP assigned to this task. Used to prevent same IP hitting multiple stores on same platform.';
