-- Add DingTalk user binding to agent_instances
-- Allows a DingTalk user to be bound to a specific agent instance
-- so the central DingTalk router can forward messages to the correct container.

ALTER TABLE agent_instances
  ADD COLUMN IF NOT EXISTS dingtalk_user_id VARCHAR(100);  -- DingTalk senderStaffId

CREATE INDEX IF NOT EXISTS idx_agent_instances_dingtalk_user
  ON agent_instances(dingtalk_user_id)
  WHERE dingtalk_user_id IS NOT NULL;
