Database Health
CRITICAL RULES
- NEVER run
drizzle-kit push— it mutates the database directly, bypassing migration files. Always usebunx drizzle-kit generateto create migration SQL, then let the Vercel build step apply it. - NEVER run DDL (
ALTER TABLE,DROP,CREATE TABLE) directly against any shared Neon branch. - NEVER edit or reorder files in
drizzle/— the migration journal tracks sequence. If you need to fix a migration, generate a new corrective one. - ALWAYS check which branch you're connected to before any database operation.
Quick Health Check
Run the full health check:
./scripts/db-health.sh
This validates: connection string, Neon branch, drizzle-kit check, migration journal integrity, and table count.
Branch Check
Before any database work, confirm your target:
./scripts/db-branch-check.sh
This script will fail with exit code 1 if you're connected to production (Neon main branch) unless you pass --allow-production.
Known Endpoints
| Endpoint | Branch | Environment |
|---|---|---|
ep-rapid-pond-akug8qa3 | main | PRODUCTION |
ep-restless-moon-akqogjx1 | staging | Preview/Development |
If the endpoint is unknown, the script uses the Neon API (NEON_API_KEY) to resolve it.
Schema Change Workflow
- Edit
lib/schema.ts - Run
./scripts/db-branch-check.sh— confirm you're NOT on production - Generate migration:
bunx drizzle-kit generate - Validate:
bun run db:check - Review the generated SQL in
drizzle/NNNN_*.sql - Run full health check:
./scripts/db-health.sh - Commit the migration files alongside the schema change
Never apply migrations manually. The Vercel build step runs migrations automatically using DATABASE_URL_UNPOOLED (direct connection, not pooled).
Pooled vs Unpooled URLs
DATABASE_URL— pooled (via pgbouncer). Use for runtime queries. Cannot run DDL.DATABASE_URL_UNPOOLED— direct. Used by Drizzle migrations at build time. Required for DDL.
Both must point at the same Neon branch.
The Staging-as-Default Quirk
The Neon-Vercel integration uses the Neon default branch for production. We set staging as default so preview branches fork from staging data. This means the integration sets Production DATABASE_URL to the wrong endpoint. Production DATABASE_URL must be set manually. See ENVIRONMENT.md for the full matrix.
Neon Project Details
- Project ID:
solitary-tooth-56221123 - Region:
aws-us-west-2 - API:
NEON_API_KEYin GitHub org secrets