ALTER TABLE sales_automation_tasks ADD COLUMN locked_at TEXT;
ALTER TABLE sales_automation_tasks ADD COLUMN locked_by TEXT;
ALTER TABLE sales_automation_tasks ADD COLUMN completed_at TEXT;
ALTER TABLE sales_automation_tasks ADD COLUMN failed_at TEXT;
ALTER TABLE sales_automation_tasks ADD COLUMN 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);
