Database Provider Options
Neon DB (Recommended)
- Serverless PostgreSQL with automatic scaling
- Generous free tier (512MB storage, 10GB data transfer)
- Instant database creation with endpoint URL
- Branch-based development for testing
- Built-in connection pooling
- Excellent performance and reliability
Alternative PostgreSQL Providers
- Supabase - PostgreSQL + additional services (auth, storage, real-time)
- Railway - Simple deployment platform with PostgreSQL
- PlanetScale - MySQL alternative (requires schema changes)
- Local PostgreSQL - For development only
This guide focuses on Neon DB as the primary option, with notes for other
PostgreSQL-compatible providers.
Quick Setup with Neon DB
1
Create Neon DB Account
- Visit neon.tech and sign up for a free account
- Click "Create a project"
- Choose your region (closest to your users for best performance)
- Give your project a meaningful name (e.g., "my-saas-app")
2
Get Database URL
After project creation, you'll see the connection details:Copy the Database URL - you'll need it for environment configuration.
# Example Neon DB connection string
postgresql://username:password@endpoint.neon.tech/dbname?sslmode=require3
Configure Environment Variables
Using the CLI tool (recommended):Or manually add to your
pnpm init:env.env.local:DATABASE_URL="postgresql://username:password@endpoint.neon.tech/dbname?sslmode=require"Only
DATABASE_URL is required. The application uses this for all database connections.4
Test Connection
Verify your database connection:You should see: "✅ Database connection successful"
pnpm db:checkInitialize Database Schema
Critical Setup Required: This application uses UUID primary keys throughout the database schema. You must enable the UUID extension before running any migrations:
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";1
Enable UUID Extension
REQUIRED FIRST STEP: Connect to your database and enable UUID support:Option 1: Using Neon DB ConsoleOption 2: Using any PostgreSQL client
- Go to your Neon project dashboard
- Open SQL Editor
- Run this command:
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";CREATE EXTENSION IF NOT EXISTS "uuid-ossp";Without this extension, all database operations will fail as the schema uses UUID primary keys throughout.
2
Push Initial Schema
After enabling UUID, create the database tables:This creates all necessary tables for:
# Push schema to database (creates tables)
pnpm db:push- User authentication and profiles (UUID IDs)
- Organizations and memberships (UUID IDs)
- Subscriptions and billing (UUID IDs)
- Blog posts and content (UUID IDs)
- Blog posts and content
3
Seed Demo Data
Populate your database with demo data for development:This creates:
# Add demo users, organizations, and sample data
pnpm db:seed- Demo admin user (
admin@example.com) - Demo regular user (
user@example.com) - Sample organization with projects
- Test subscription plans
4
Open Database Studio
Explore your data with Drizzle Studio:Access the studio at
# Opens database management interface
pnpm db:studiohttp://localhost:4983 to view and edit your data.Neon DB Features
Database Branching
Neon DB supports branching for safe development:# Your production database
postgresql://username:password@main-endpoint.neon.tech/dbnameConnection Pooling
Neon DB includes automatic connection pooling:# Pooled connection (default)
DATABASE_URL="postgresql://username:password@endpoint.neon.tech/dbname?sslmode=require"
# Direct connection (if needed)
DIRECT_URL="postgresql://username:password@endpoint.neon.tech/dbname?sslmode=require&pgbouncer=true"Monitoring and Analytics
- Query performance insights in Neon console
- Connection monitoring and usage statistics
- Automatic backups and point-in-time recovery
- Usage alerts for free tier limits
Alternative Provider Setup
Supabase PostgreSQL
If you prefer Supabase for additional services:1
Create Supabase Project
- Visit supabase.com and create account
- Create new project with PostgreSQL
- Get connection string from Settings → Database
2
Configure URLs
# Supabase provides both pooled and direct connections
DATABASE_URL="postgresql://postgres.pooler:password@host:6543/postgres"
DIRECT_URL="postgresql://postgres:password@host:5432/postgres"Railway PostgreSQL
For Railway deployments:1
Add PostgreSQL Service
- Create Railway project
- Add PostgreSQL service from templates
- Get connection URL from service variables
2
Configure Environment
DATABASE_URL="postgresql://postgres:password@host:port/railway"
DIRECT_URL="postgresql://postgres:password@host:port/railway"Local PostgreSQL
For local development only:1
Install PostgreSQL
# macOS with Homebrew
brew install postgresql
brew services start postgresql
# Ubuntu/Debian
sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresql2
Create Database
# Create database and user
createdb my_saas_app
createuser -s my_user
# Set password
psql -c "ALTER USER my_user PASSWORD 'my_password';"3
Configure Local URL
DATABASE_URL="postgresql://my_user:my_password@localhost:5432/my_saas_app"
DIRECT_URL="postgresql://my_user:my_password@localhost:5432/my_saas_app"Database Management Commands
Schema Management
# Generate migration files
pnpm db:generate
# Apply migrations to database
pnpm db:migrate
# Push schema changes directly (development)
pnpm db:push
# Reset database (destructive)
pnpm db:clearData Management
# Seed database with demo data
pnpm db:seed
# Reset and re-seed (fresh start)
pnpm db:reset-seed
# Open database studio
pnpm db:studioProduction Commands
# Run migrations in production
NODE_ENV=production pnpm db:migrate
# Check database health
pnpm db:checkTroubleshooting
Connection Issues
# Test database connection
pnpm db:check
# Common issues:
# 1. Incorrect DATABASE_URL format
# 2. Network/firewall blocking connection
# 3. Database not accepting connections
# 4. SSL mode configurationMigration Errors
# Reset migrations (development only)
rm -rf drizzle/
# Generate fresh migrations
pnpm db:generate
# Apply to database
pnpm db:pushSSL Certificate Issues
# For providers requiring SSL
DATABASE_URL="postgresql://user:pass@host:port/db?sslmode=require"
# Disable SSL for local development
DATABASE_URL="postgresql://user:pass@localhost:5432/db?sslmode=disable"Security Best Practices
Connection Security
- Always use SSL in production (
sslmode=require) - Restrict database access to application servers only
- Use connection pooling to manage connections efficiently
- Monitor connection usage to detect anomalies
Credentials Management
- Never commit database URLs to version control
- Use environment variables for all database configuration
- Rotate database passwords regularly
- Use read-only users for reporting queries
Backup Strategy
- Enable automatic backups (Neon DB includes this)
- Test restore procedures regularly
- Keep backups encrypted and secure
- Document recovery procedures
Your database is now configured! Continue with the First
Run guide to test your complete setup.
Next Steps
After database setup:- First Run - Test your complete configuration
- Authentication - Configure authentication providers
- Deployment - Deploy to production
Pro tip: Use Neon DB branching to create separate databases for
development, staging, and production environments safely.