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]>
11 lines
709 B
SQL
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';
|