Database Setup & Configuration

diy-analytics stores all data in PostgreSQL, using Drizzle ORM and the postgres-js driver. Any standard PostgreSQL 14+ database with SSL works.


Why connection pooling matters

Serverless platforms like Vercel spin up many short-lived compute workers under load. If each worker opens a direct connection to Postgres, you'll exceed max_connections and start dropping requests.

A connection pooler — PgBouncer, or the native poolers built into Neon and Supabase — keeps a shared pool of persistent connections and multiplexes requests across them in transaction mode.


Supported providers


In your Neon dashboard:

  1. Select your database branch.
  2. In the connection details, toggle to Pooled connection — look for the -pooler subdomain.
  3. Copy the URI:
bash
DATABASE_URL=postgres://user:password@ep-xxxx-pooler.us-east-2.aws.neon.tech/neondb?sslmode=require

2. Supabase

In your Supabase project dashboard:

  1. Go to Project Settings → Database → Connection string.
  2. Select Transaction Mode (port 6543) — not Session Mode (port 5432).
  3. Copy the pooled URI:
bash
DATABASE_URL=postgres://postgres.xxxx:password@aws-0-region.pooler.supabase.com:6543/postgres

No additional Supabase SDKs or anon keys are needed — diy-analytics connects over standard PostgreSQL.

3. Vercel Postgres

If you're using the Vercel Postgres / Neon integration:

bash
DATABASE_URL=postgres://default:password@ep-xxxx-pooler.postgres.vercel-storage.com/verceldb?sslmode=require

4. Railway & self-hosted PostgreSQL

Any standard PostgreSQL connection string works:

bash
DATABASE_URL=postgres://postgres:password@localhost:5432/diy-analytics?sslmode=disable

5. Local Docker container

For local development and contributions:

bash
1docker run --name diy-postgres \ 2 -e POSTGRES_PASSWORD=password \ 3 -e POSTGRES_DB=diy-analytics \ 4 -p 5432:5432 \ 5 -d postgres:16-alpine

Applying schema migrations

When provisioning a new database, or upgrading an existing deployment, run the Drizzle migration runner:

bash
npm run db:migrate

Database commands

CommandDescription
npm run db:migrateApplies all pending SQL migrations to DATABASE_URL
npm run db:generateGenerates new migration files after editing src/lib/schema/
npx drizzle-kit studioOpens Drizzle Studio, a browser UI for your tables

Next steps