For the complete documentation index, see llms.txt. Prefer markdown by appending.mdto documentation URLs or sendingAccept: text/markdown.
Schema
Add an application table beside the generated auth schema, export it from the schema barrel, and create a reviewed SQLite migration.
Keep your own tables out of the generated auth file. pnpm db:generate runs Better Auth with --output src/db/schema/auth.ts --yes, so anything you add to that file is removed the next time the script runs.
Application tables live next to it, under src/db/schema/. The example below adds a new notes table - these files do not ship in the kit by default.
Create new table
Create src/db/schema/note.ts. Import user from the auth file to use it for relations:
import { sqliteTable, text } from "drizzle-orm/sqlite-core";
import { user } from "./auth";
export const note = sqliteTable("note", {
id: text("id").primaryKey(),
userId: text("user_id")
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
title: text("title").notNull(),
});The foreign key ties notes to individual users. Cascading deletion removes their notes when the auth user is deleted. Choose the deletion policy deliberately for your own data, especially records that need to survive account deletion.
Export it
Add the new file to src/db/schema/index.ts:
export * from "./auth";
export * from "./note";src/db/index.ts and src/db/script.ts already pass this barrel to Drizzle. drizzle.config.ts points Drizzle Kit at src/db/schema/index.ts, so the same export is what migration generation sees. After it, import { note } from "@/db/schema" works in server code, and db.query.note is available.
Do not rename the existing Better Auth tables or change the adapter's provider: "sqlite". If you extend a Better Auth user field, declare it in the auth configuration so the generator includes it in auth.ts. See Better Auth schema extensions.
Generate and inspect the migration
For an application-only table change, generate SQL from the existing schema without rerunning auth generation:
pnpm exec drizzle-kit generateWhen auth configuration or plugins change, use the combined script:
pnpm db:generateBoth paths write migrations to drizzle/. Review the SQL before applying it. A new note table should create that table and its foreign key. Unexpected drops of auth or application tables mean a schema file is missing from the barrel.
pnpm db:migrate --localCheck the new table locally:
pnpm wrangler d1 execute DB --local --command "PRAGMA table_info('note');"Once the local path works, follow migration deployment. For a full UI-to-database implementation, use add a feature.
How is this guide?
Last updated on