suna/backend/supabase/migrations/20250127000000_add_agent_id...

15 lines
468 B
SQL

ALTER TABLE threads ADD COLUMN agent_id UUID REFERENCES agents(agent_id) ON DELETE SET NULL;
CREATE INDEX idx_threads_agent_id ON threads(agent_id);
UPDATE threads
SET agent_id = (
SELECT a.agent_id
FROM agents a
WHERE a.account_id = threads.account_id
AND a.is_default = true
LIMIT 1
)
WHERE agent_id IS NULL;
COMMENT ON COLUMN threads.agent_id IS 'ID of the agent used for this conversation thread. If NULL, uses account default agent.';