This project uses SQLite for the database — either Cloudflare D1 (production) or Bun bun:sqlite (local Node.js/Bun runtime).
cd backend
bun run db:create
# or: npx wrangler d1 create auth-dbCopy the database_id from the output and update wrangler.toml:
[[d1_databases]]
binding = "DB"
database_name = "auth-db"
database_id = "your-database-id-here"# Local development
bun run db:migrate:local
# Production
bun run db:migratenpx wrangler d1 migrations list DB --local
npx wrangler d1 migrations list DB --remote# Local
npx wrangler d1 execute DB --local --command "SELECT * FROM user"
# Production
npx wrangler d1 execute DB --remote --command "SELECT * FROM user"When using bun run dev:node, the database is created automatically at ./data/local.db. Migrations run on startup.
# Install sqlite3 CLI if needed
brew install sqlite3 # macOS
# Open database
sqlite3 ./backend/data/local.db
# Common queries
.tables
SELECT * FROM user;
SELECT * FROM session;
.quitBetter Auth creates these tables:
| Table | Purpose |
|---|---|
user |
User profiles (id, name, email, image) |
session |
Active sessions with tokens |
account |
Linked accounts (OAuth, credentials) |
verification |
Email verification & OTP tokens |
# D1 way
npx wrangler d1 migrations create DB add-custom-tableThis creates migrations/0002_add-custom-table.sql.
CREATE TABLE IF NOT EXISTS user_preferences (
user_id TEXT NOT NULL REFERENCES user(id),
theme TEXT DEFAULT 'light',
notifications INTEGER DEFAULT 1,
PRIMARY KEY (user_id)
);bun run db:migrate:local # local
bun run db:migrate # production# Check current state
npx wrangler d1 migrations list DB --local
# Check what's in the database
npx wrangler d1 execute DB --local --command ".tables"# D1 local — delete wrangler state
rm -rf .wrangler/state
# Re-apply migrations
bun run db:migrate:local
# SQLite local — delete the file
rm ./data/local.db
bun run dev:node # recreates on startupEnsure database_id in wrangler.toml matches your actual D1 database. Run npx wrangler d1 list to see available databases.
D1 has automatic point-in-time recovery via Cloudflare dashboard.
Export manually:
npx wrangler d1 export DB --remote --output backup.sqlcp ./data/local.db ./data/local.db.backup