ALTER TABLE sales_automation_tasks ADD COLUMN IF NOT EXISTS locked_at TEXT;
ALTER TABLE sales_automation_tasks ADD COLUMN IF NOT EXISTS locked_by TEXT;
ALTER TABLE sales_automation_tasks ADD COLUMN IF NOT EXISTS completed_at TEXT;
ALTER TABLE sales_automation_tasks ADD COLUMN IF NOT EXISTS failed_at TEXT;
ALTER TABLE sales_automation_tasks ADD COLUMN IF NOT EXISTS max_retries INTEGER NOT NULL DEFAULT 3;

CREATE INDEX IF NOT EXISTS idx_sales_tasks_lock ON sales_automation_tasks(status, locked_at, locked_by);
