Files
STCourses/packages/feature-ai/migrations/0001_ai_message_citations.sql
T
Lucas WintherandClaude Opus 5.5 d34a5c1f0c feat(ai): citations column on ai_messages (contract request 5)
New packages/feature-ai/migrations/0001_ai_message_citations.sql adds
ai_messages.citations_json and folds v1 'sources' rows into the assistant
row before them. The feature writes and reads the column directly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-30 20:28:23 +01:00

11 lines
709 B
SQL

-- v1.1 (contract request 5): an assistant message's citations live in its own column.
-- v1 stored them as an extra row with role 'sources' right after the assistant row (ids sort in write order).
-- Fold each such row into the assistant row before it, then drop every 'sources' row.
ALTER TABLE ai_messages ADD COLUMN citations_json TEXT;
UPDATE ai_messages SET citations_json = (
SELECT s.content FROM ai_messages s
WHERE s.conversation_id = ai_messages.conversation_id AND s.role = 'sources'
AND s.id = (SELECT MIN(n.id) FROM ai_messages n WHERE n.conversation_id = ai_messages.conversation_id AND n.id > ai_messages.id)
) WHERE role = 'assistant';
DELETE FROM ai_messages WHERE role = 'sources';