Importing from the Vercel template
The ai-chatbot template's Chat and Message_v2 tables map straight across.
If you started from Vercel's ai-chatbot template, its Chat and Message_v2 tables map straight across - it already stores UIMessage parts, so this is a copy plus the parent chain this schema uses.
npx ai-sdk-threads import-vercel --database-url "$DATABASE_URL" --dry-run
npx ai-sdk-threads import-vercel --database-url "$DATABASE_URL"Threads that already exist are skipped, so a rerun after a partial import is safe.
Against a database handle you already have
Both commands are exported, if you would rather run them programmatically than pass a connection string:
import { importVercelChat, migrateDatabase } from "ai-sdk-threads/cli";What the import does
- Each
Chatrow becomes anai_sdk_threadsrow, keeping its id anduserId. - Each
Message_v2row becomes anai_sdk_messagesrow with itspartsverbatim. - Messages are chained into a linear
parent_idpath increatedAtorder, and the thread'sactive_leaf_idis set to the last one - so the imported conversation is the live path and branching works from there on. - Rows are stamped with the
aimajor that the store is configured for.
The CLI needs a Postgres driver of its own - npm i -D pg - because this package ships none.
Why Message_v2 exists at all
The template carries a Message_v2 table because migrating the original Message table in place was not practical when the stored shape changed. That is the problem sdk_version exists to avoid here - see Migrating.