Files
coder/coderd/database/migrations/000476_chat_pin_order_constraints.up.sql
T
Cian Johnston c602a31856 fix(coderd): reject pinning child chats in patchChat handler (#24669)
The UI already prevents child (delegated/subagent) chats from being
pinned, but the `PATCH /api/experimental/chats/{chat}` endpoint did not
enforce this. A direct API call could pin a child chat.

- Add a `400 Bad Request` guard in `patchChat` when `pinOrder > 0` and
the chat has a `ParentChatID`
- Add `TestChatPinOrder/RejectsChildChat` test

> 🤖
2026-04-23 18:36:20 +01:00

15 lines
473 B
SQL

-- Defensive: fix any existing violating rows before adding constraints.
UPDATE chats SET pin_order = 0
WHERE pin_order > 0 AND parent_chat_id IS NOT NULL;
UPDATE chats SET pin_order = 0
WHERE pin_order > 0 AND archived = true;
ALTER TABLE chats
ADD CONSTRAINT chats_pin_order_parent_check
CHECK (pin_order = 0 OR parent_chat_id IS NULL);
ALTER TABLE chats
ADD CONSTRAINT chats_pin_order_archived_check
CHECK (pin_order = 0 OR archived = false);