mirror of
https://github.com/coder/coder.git
synced 2026-06-03 13:08:25 +00:00
d5a1792f07
Needed by #23833 Adds a `chat_file_links` association table to track which files are associated with each chat. - `AppendChatFileIDs` query links a file to a chat with deduplication - `GetChatFileMetadataByIDs` query returns lightweight file metadata by IDs - Tool-created files (e.g. `propose_plan`) are linked to the chat after insert - User-uploaded files are linked to the chat when the referencing message is sent - Single-chat GET endpoint hydrates `files: ChatFileMetadata[]` on the response > 🤖 Created by Coder Agents and massaged into shape by a human.
18 lines
532 B
SQL
18 lines
532 B
SQL
CREATE TABLE chat_file_links (
|
|
chat_id uuid NOT NULL,
|
|
file_id uuid NOT NULL,
|
|
UNIQUE (chat_id, file_id)
|
|
);
|
|
|
|
CREATE INDEX idx_chat_file_links_chat_id ON chat_file_links (chat_id);
|
|
|
|
ALTER TABLE chat_file_links
|
|
ADD CONSTRAINT chat_file_links_chat_id_fkey
|
|
FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE;
|
|
|
|
ALTER TABLE chat_file_links
|
|
ADD CONSTRAINT chat_file_links_file_id_fkey
|
|
FOREIGN KEY (file_id) REFERENCES chat_files(id) ON DELETE CASCADE;
|
|
|
|
ALTER TABLE chats DROP COLUMN IF EXISTS file_ids;
|