- Renamed auth-service to iam-service across various files for consistency. - Updated deployment workflows, database migration scripts, and documentation to reflect the service name change. - Enhanced bilingual documentation for clarity on the new service structure and usage. - Removed outdated references to auth-service in scripts and configuration files to streamline the project structure.
2.7 KiB
2.7 KiB
Neon Database Setup
This project uses Neon PostgreSQL for all environments (dev, staging, production).
Why Neon?
- ✅ Serverless PostgreSQL with auto-scaling
- ✅ Branching support (dev, staging, production branches)
- ✅ Point-in-time restore
- ✅ Free tier for development
- ✅ Built-in connection pooling
- ✅ No infrastructure management needed
Setup Instructions
1. Create Neon Project
- Sign up at https://neon.tech
- Create a new project:
goodgo-platform - Note your connection string from the main branch
2. Create Branches
Create branches for each environment:
# Using Neon Console or CLI
# Main branch = development
# Create: staging branch
# Create: production branch
3. Get Connection Strings
For each branch, get the connection string:
- Format:
postgresql://user:password@ep-xxx.region.neon.tech/dbname?sslmode=require - Add
?pgbouncer=truefor connection pooling (recommended)
4. Configure Environment Variables
Local Development
Create deployments/local/.env.local:
DATABASE_URL=postgresql://user:pass@ep-xxx.region.neon.tech/dbname?sslmode=require&pgbouncer=true
Staging/Production
Store in GitHub Secrets:
NEON_DATABASE_URL_STAGINGNEON_DATABASE_URL_PRODUCTION
Or in Kubernetes Secrets (see deployments/staging/kubernetes/secrets.yaml.example)
Connection Pooling
Neon provides built-in connection pooling. Add ?pgbouncer=true to your connection string:
postgresql://user:pass@ep-xxx.region.neon.tech/dbname?sslmode=require&pgbouncer=true
Migration
Development
cd services/iam-service
pnpm prisma migrate dev
Staging/Production
Migrations run automatically in CI/CD workflows before deployment.
Backup & Restore
Neon provides automatic backups and point-in-time restore via their console.
For manual backup:
# Using pg_dump
pg_dump $DATABASE_URL > backup.sql
# Restore
psql $DATABASE_URL < backup.sql
Monitoring
Monitor your databases via Neon Console:
- Connection metrics
- Query performance
- Storage usage
- Branch status
Cost Optimization
- Free tier: Sufficient for development
- Staging: Use free tier or minimal paid plan
- Production: Scale based on usage
Troubleshooting
Connection Issues
- Check connection string format
- Verify SSL mode:
?sslmode=require - Check IP allowlist in Neon console (if enabled)
- Verify credentials
Migration Issues
- Ensure DATABASE_URL is set correctly
- Check Prisma schema matches database
- Review migration files
Performance Issues
- Enable connection pooling:
?pgbouncer=true - Check query performance in Neon console
- Review indexes in Prisma schema