Hosted Database Deployment
Deploy SaleSpider with a managed PostgreSQL database for simplified operations and automatic backups.
Overview
Hosted database deployment combines:
- Your application (self-hosted or cloud platform)
- Managed PostgreSQL database (Neon, Supabase, etc.)
- Automatic database backups
- Simplified maintenance
Supported Providers
- Neon - Serverless PostgreSQL
- Supabase - Open source Firebase alternative
- Railway - All-in-one platform
- Heroku Postgres - Managed PostgreSQL
- Any other hosted PostgreSQL provider
Quick Start
1. Set Up Database
Using Neon
- Create account at neon.tech
- Create new project
- Copy connection string from dashboard
- Format:
postgresql://user:password@host/database?sslmode=require
Using Supabase
- Create account at supabase.com
- Create new project
- Go to Settings → Database
- Copy connection string (use "Connection pooling" for production)
- Format:
postgresql://postgres:password@host:6543/postgres
Using Railway
- Create account at railway.app
- Create new project
- Add PostgreSQL database
- Copy
DATABASE_URLfrom variables - Railway auto-configures the connection
2. Configure Application
Create .env file:
# Database (from your provider)
DATABASE_URL="postgresql://user:password@host:5432/database?sslmode=require"
# Authentication
JWT_SECRET="your-super-secret-jwt-key-change-this"
JWT_EXPIRES_IN="7d"
# AI Features (optional)
GOOGLE_GENAI_API_KEY="your-google-ai-api-key"
# Application
NODE_ENV="production"
NEXT_PUBLIC_APP_URL="https://yourdomain.com"
# Disable local backups (provider handles this)
SETUP_BACKUP="false"
PGBACKREST_REPO1_TYPE="none"3. Deploy Application
Option A: Docker with Hosted Database
# Use hosted database compose file
docker-compose -f docker-compose.hosted-db.yml up -d
# Run migrations
docker-compose exec app npx prisma migrate deploy
# Seed database
docker-compose exec app npm run seedOption B: Cloud Platform
Deploy to Vercel, Railway, or Render:
# Set environment variables on platform
DATABASE_URL=your-connection-string
JWT_SECRET=your-secret
SETUP_BACKUP=false
# Deploy
vercel --prod
# or
railway up
# or
render deploy4. Initialize Database
# Run migrations and seed data
npx prisma migrate deploy
npm run seed:prodProvider-Specific Guides
Neon Configuration
Connection String Format:
postgresql://user:password@ep-xxx.region.aws.neon.tech/dbname?sslmode=requireBest Practices:
- Use connection pooling for production
- Enable autoscaling for variable load
- Set up branch databases for development
Environment Variables:
DATABASE_URL="postgresql://user:password@ep-xxx.region.aws.neon.tech/dbname?sslmode=require"
SETUP_BACKUP="false"Supabase Configuration
Connection String Format:
postgresql://postgres:password@db.xxx.supabase.co:6543/postgresBest Practices:
- Use connection pooling (port 6543) for applications
- Use direct connection (port 5432) for migrations
- Enable SSL mode
Environment Variables:
# For application (pooled)
DATABASE_URL="postgresql://postgres:password@db.xxx.supabase.co:6543/postgres"
# For migrations (direct)
DIRECT_URL="postgresql://postgres:password@db.xxx.supabase.co:5432/postgres"
SETUP_BACKUP="false"Railway Configuration
Automatic Setup: Railway automatically sets DATABASE_URL when you add PostgreSQL.
Best Practices:
- Use Railway's built-in PostgreSQL
- Enable automatic backups in dashboard
- Use private networking
Environment Variables:
# Railway sets this automatically
DATABASE_URL=${{Postgres.DATABASE_URL}}
SETUP_BACKUP="false"Heroku Postgres Configuration
Connection String Format:
postgresql://user:password@host.compute.amazonaws.com:5432/databaseBest Practices:
- Use hobby-dev tier for testing
- Upgrade to standard for production
- Enable automated backups
Environment Variables:
DATABASE_URL="postgresql://user:password@host.compute.amazonaws.com:5432/database"
SETUP_BACKUP="false"Docker Compose Configuration
Hosted Database Setup
Use the provided docker-compose.hosted-db.yml:
version: "3.8"
services:
app:
build: .
ports:
- "3000:3000"
environment:
- DATABASE_URL=${DATABASE_URL}
- JWT_SECRET=${JWT_SECRET}
- SETUP_BACKUP=false
restart: unless-stoppedNo PostgreSQL container needed!
Backup Management
Provider-Managed Backups
All supported providers handle backups automatically:
Neon:
- Automatic daily backups
- Point-in-time recovery
- Branch databases for testing
Supabase:
- Daily automated backups
- Manual backup creation
- Point-in-time recovery (paid plans)
Railway:
- Automatic backups
- One-click restore
- Backup retention based on plan
Heroku:
- Automated daily backups
- Manual backup creation
- Backup retention based on plan
Accessing Backups
Check your provider's dashboard:
- Neon: Project → Backups
- Supabase: Database → Backups
- Railway: Database → Backups
- Heroku: Resources → Postgres → Durability
Migration from Self-Hosted
1. Export Current Database
# Create backup
pg_dump $DATABASE_URL > backup.sql
# Or using Docker
docker-compose exec postgres pg_dump -U salespider salespider > backup.sql2. Import to Hosted Database
# Import to new database
psql $NEW_DATABASE_URL < backup.sql3. Update Configuration
# Update .env
DATABASE_URL="new-hosted-database-url"
SETUP_BACKUP="false"4. Restart Application
docker-compose restart app
# or redeploy to cloud platformMonitoring
Database Metrics
Check provider dashboards for:
- Connection count
- Query performance
- Storage usage
- CPU and memory usage
Application Monitoring
# Check application logs
docker-compose logs -f app
# Monitor connections
# Check provider dashboardTroubleshooting
Connection Issues
SSL Required Error:
# Add sslmode to connection string
DATABASE_URL="postgresql://user:pass@host/db?sslmode=require"Connection Timeout:
- Check firewall rules
- Verify IP whitelist (if applicable)
- Check connection limits
Too Many Connections:
- Use connection pooling
- Reduce max connections in app
- Upgrade database plan
Migration Issues
Migration Fails:
# Use direct connection for migrations
DIRECT_URL="postgresql://user:pass@host:5432/db"
# Run migrations
npx prisma migrate deploy --schema=./prisma/schema.prismaSchema Drift:
# Reset and reapply
npx prisma migrate reset
npx prisma migrate deploySecurity
Connection Security
- Always use SSL/TLS
- Use connection pooling
- Rotate credentials regularly
- Restrict IP access (if available)
Access Control
- Use strong passwords
- Enable 2FA on provider account
- Limit database user permissions
- Use read-only replicas for reporting
Benefits
- ✅ Managed Backups - Automatic daily backups
- ✅ Automatic Updates - Provider handles maintenance
- ✅ Scalability - Easy to scale up/down
- ✅ High Availability - Built-in redundancy
- ✅ Monitoring - Provider dashboards
- ✅ Support - Provider technical support
Limitations
- ⚠️ Internet Required - Needs connectivity
- ⚠️ Recurring Costs - Monthly subscription
- ⚠️ Provider Lock-in - Migration effort required
- ⚠️ Less Control - Limited configuration options