Overview
The originalMessage table used a simple content field to store message data. The new Message_v2 table introduces a parts field that supports multi-modal message content and better represents the structure of AI SDK messages.
What changed
Schema migration
The database schema has been updated to use a parts-based structure:The new schema replaces
lib/db/schema.ts
content with parts and adds an attachments field for file uploads.Migration steps
Update your database
Run the database migration to create the new tables:This will create the
Message_v2 and Vote_v2 tables alongside the existing tables.Update message saving
Update your code to save messages with the parts structure. Here’s how it’s done in the chat API:
app/(chat)/api/chat/route.ts
Parts structure
Theparts field is an array that can contain different types of content:
Text parts
Text parts
Tool call parts
Tool call parts
Tool result parts
Tool result parts
Benefits of parts-based messages
The new parts-based structure provides several advantages:- Multi-modal support: Messages can contain multiple types of content (text, tool calls, tool results)
- Better AI SDK alignment: The structure matches the AI SDK’s message format
- Streaming support: Parts can be streamed individually for better UX
- Tool integration: Tool calls and results are first-class message components
- Type safety: TypeScript types are more accurate and helpful
Handling tool calls
With the new structure, tool calls are represented as message parts:app/(chat)/api/chat/route.ts
The
parts field automatically includes all text content, tool calls, and tool results from the AI SDK’s streaming response.Backward compatibility
The deprecated tables will remain in the database until you’re ready to remove them. However:- New features will only support the
Message_v2structure - The deprecated tables are marked with
DEPRECATEDcomments in the schema - You should plan to migrate all existing data and remove the old tables
Next steps
- Review the streaming guide to understand how parts are streamed
- Learn about building AI tools that integrate with the parts system
- See the upgrading guide for version migration information