Run persistence schema changes as migrations. A change on the first production request can fail under load or race across instances.
Your adapter owns its schema. TanStack AI never reads your tables, so you choose the table layout and how changes are applied. Apply each change before you deploy the code that uses it.
A hand-written adapter can create its tables the first time it opens the database. The SQLite example in Build your own adapter does this behind a migrate flag with CREATE TABLE IF NOT EXISTS, so you can run it many times:
import { sqlitePersistence } from './sqlite-persistence'
const persistence = sqlitePersistence({
url: 'file:.data/state.sqlite',
migrate: true,
})This is good for local development and tests. Do not run migrations at request time in production.
If you build the adapter with an ORM or a query builder, let that tool own the migration history:
The adapter skills in @tanstack/ai-persistence cover each of these workflows.
You can map the store contracts onto tables you already have. See Build your own adapter.
Then those tables are part of your app schema, and your current migration tool owns them: