Skip to Content
StackBlaze Templates — operator documentation

Database

The template uses PostgreSQL with Drizzle ORM. Locally it runs in Docker; in production you point it at any managed Postgres.

Local (Docker)

The bundled docker-compose.yml runs Postgres on host port 5432 by default:

docker compose up -d

The DATABASE_URL in .env.example already targets it, so a fresh project works without changes:

postgresql://stackblaze:stackblaze@localhost:5432/stackblaze

If port 5432 is already in use — commonly by a system-installed Postgres — remap the container with POSTGRES_PORT and update DATABASE_URL to match:

POSTGRES_PORT=5433 docker compose up -d
postgresql://stackblaze:stackblaze@localhost:5433/stackblaze

Production

Use any managed Postgres — Supabase, Neon, Railway, AWS RDS, Azure, GCP, or a Vercel Marketplace database. Set DATABASE_URL to its connection string.

Most hosted providers require SSL — append ?sslmode=require to the connection string if connections are rejected.

Schema management

The schema is defined in lib/db/schema.ts. Two workflows:

CommandUse
npm run db:pushPush the schema directly — fast, good for dev and first prod setup.
npm run db:generateGenerate versioned migration files under drizzle/.
npm run db:studioOpen Drizzle Studio (a database GUI).

Auth tables are generated by better-auth. After changing auth config, run npm run auth:generate (rewrites lib/db/schema.ts) then npm run db:push.

Test database

Integration tests use a separate database (TEST_DATABASE_URL). Create it once in your Postgres instance:

docker exec stackblaze-postgres psql -U stackblaze -d stackblaze \ -c "CREATE DATABASE stackblaze_test;"