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.
Always connect with a pooled connection URI in production — the -pooler subdomain on Neon, or port 6543 on Supabase.
Supported providers
Neon
Serverless pooled Postgres
Supabase
Transaction pooler (6543)
Vercel Postgres
Neon storage integration
Railway
Standard Postgres instance
1. Neon (serverless Postgres) — recommended
In your Neon dashboard:
- Select your database branch.
- In the connection details, toggle to Pooled connection — look for the
-poolersubdomain. - Copy the URI:
Free-tier Neon databases suspend compute after a period of inactivity. The next query wakes it up in roughly 500ms. To avoid this in production, disable auto-suspend in your Neon compute settings.
2. Supabase
In your Supabase project dashboard:
- Go to Project Settings → Database → Connection string.
- Select Transaction Mode (port
6543) — not Session Mode (port5432). - Copy the pooled URI:
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:
4. Railway & self-hosted PostgreSQL
Any standard PostgreSQL connection string works:
5. Local Docker container
For local development and contributions:
Applying schema migrations
When provisioning a new database, or upgrading an existing deployment, run the Drizzle migration runner:
Database commands
| Command | Description |
|---|---|
npm run db:migrate | Applies all pending SQL migrations to DATABASE_URL |
npm run db:generate | Generates new migration files after editing src/lib/schema/ |
npx drizzle-kit studio | Opens Drizzle Studio, a browser UI for your tables |