Database

Postgres + Drizzle ORM setup and the starter schema.

Overview

The starter uses:

  • PostgreSQL for persistence
  • Drizzle ORM for schema + queries

Schema file: tanstarter/src/db/schema.ts
DB connection: tanstarter/src/db/index.ts
Drizzle config: tanstarter/drizzle.config.ts

1) Set DATABASE_URL

In tanstarter/.env:

DATABASE_URL=postgresql://username:password@localhost:5432/database_name

Recommended: Supabase Postgres

Supabase is a solid default because it’s quick to set up and works well with Postgres + Drizzle.

  1. Create a project: Supabase
  2. Set a strong database password during project creation.
  3. Go to Project Settings → Database and copy a connection string.
  4. Set that value as DATABASE_URL in tanstarter/.env.

Supabase docs:

Local Postgres (Docker)

If you don’t have Postgres installed, this is the fastest path:

docker run --name tanstarter-postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=tanstarter -p 5432:5432 -d postgres:16

Then use:

DATABASE_URL=postgresql://postgres:postgres@localhost:5432/tanstarter

2) Apply the schema

For local dev, the simplest path is:

bun run db:push

Optional: open Drizzle Studio:

bun run db:studio

Migrations (recommended for production)

When you change tanstarter/src/db/schema.ts:

bun run db:generate
bun run db:migrate

What tables exist

Core tables you’ll see in tanstarter/src/db/schema.ts:

  • Auth: user, session, account, verification
  • Billing: subscriptions
  • AI prompts: prompts

If you add your own tables, keep them in the same schema file (or import additional schema files from it).