Pre-Deployment Checklist
Before starting deployment, ensure:- All prerequisites are met
- Environment variables are configured
- Database is set up and tested
- Code is committed to version control (Git)
- Production secrets are generated and secure
- Backup of current production database (if updating)
Deployment Architecture
Phase 1: Database Migration
1.1 Backup Production Database
This step is mandatory before any production changes. It provides a rollback point if issues arise.
Alternative: CockroachDB Native Backup
Alternative: CockroachDB Native Backup
If you have S3 configured:
1.2 Generate Migration Plan
This creates a SQL script showing exactly what will change:1.3 Review Migration Script
Openmigration_plan_YYYYMMDD.sql and look for:
✅ Safe Operations
✅ Safe Operations
CREATE TABLE- New features (e.g.,ReportSession)ALTER TABLE ... ADD COLUMN- New fields (e.g.,User.supervisorId)CREATE INDEX- Performance improvementsALTER TABLE ... ADD CONSTRAINT- Data integrity
⚠️ Review Carefully
⚠️ Review Carefully
ALTER TABLE ... ALTER COLUMN- Type changesALTER TABLE ... DROP CONSTRAINT- Removing relationships- Any operation on tables with large datasets
❌ Dangerous Operations
❌ Dangerous Operations
DROP TABLE- Data lossALTER TABLE ... DROP COLUMN- Permanent deletionTRUNCATE- Removes all data
1.4 Apply Schema Changes
Once verified safe:This approach is safer than
prisma db push because it shows exactly what will change before applying.Phase 2: Backend Deployment
2.1 Build Backend
dist/ directory with compiled JavaScript.
2.2 Deploy to Hosting Platform
- Render
- Plesk
- Custom VPS
Configure Render service
In your Render dashboard:
- Build Command:
npm install && npx prisma generate && npm run build - Start Command:
npm start - Node Version: 18 or higher
Set environment variables
Add all backend environment variables from Environment Configuration:
DATABASE_URL(with connection pooling)DIRECT_URLJWT_SECRETCLOUDINARY_*CORS_ORIGIN(set to your frontend URL)
2.3 Verify Backend Health
Phase 3: Frontend Deployment
3.1 Build Frontend
Next.js will build with Turbopack for optimized production bundles.
3.2 Deploy to Hosting Platform
- Vercel (Recommended)
- Netlify
- Self-Hosted
Configure project
- Set up and deploy? Y
- Link to existing project? N (first time)
- Project name:
millennium-potters - Framework: Next.js (auto-detected)
3.3 Verify Frontend Deployment
Phase 4: Post-Deployment Verification
4.1 Functional Tests
Authentication
Authentication
- Admin login works
- Supervisor login works
- Credit Officer login works
- Logout works
- Token refresh works (wait 5 minutes, refresh page)
Data Integrity
Data Integrity
- User count matches pre-deployment
- Loan count matches pre-deployment
- Union count matches pre-deployment
- Old loans display correctly
- Old member profiles load
Core Features
Core Features
- Create a test union
- Create a test member
- Create a test loan
- Record a test repayment
- Upload a test document
- Generate a report
UI/UX
UI/UX
- Dark mode toggle works
- Mobile responsive design
- Command Center tour launches
- All pages load without errors
4.2 Performance Checks
Expected Metrics
Expected Metrics
- API Health Check: < 200ms
- Dashboard Load: < 2s
- Loan List Load: < 1s (for 100 loans)
- Database Query: < 100ms (average)
4.3 Security Verification
Maintenance Mode
For safe deployments, enable maintenance mode to prevent user actions during updates:Enable Maintenance Mode
- Non-admin users see “Under Maintenance” message
- Admins can still access the system
- All data modification endpoints return 503
Disable After Deployment
Backup Strategy
Automated Backups
CockroachDB provides:- Hourly backups (automatic)
- 30-day retention
- Point-in-Time Recovery to any point in last 30 days
Application-Level Backups
The system includes built-in backup features:- Go to: Dashboard → Settings → Backup
- Configure:
- Frequency: Daily/Weekly/Monthly
- Location: Cloud (Cloudinary)
- Retention: 30 days (default)
- Manual Backup: Click “Backup Now”
Application backups are JSON exports stored in Cloudinary, separate from database backups.
Rollback Procedure
If deployment fails:Monitoring and Logging
Health Monitoring
Set up uptime monitoring with:- UptimeRobot (free)
- Pingdom
- New Relic
/healthendpoint every 5 minutes- Alert if down for > 2 minutes
Log Aggregation
For backend logs:- Render
- PM2
View logs in Render dashboard:
- Go to your service
- Click “Logs” tab
- Filter by error level
Audit Logs
All user actions are logged in theAuditLog table:
Troubleshooting
500 Internal Server Error
500 Internal Server Error
Possible Causes:
- Database connection failed
- Missing environment variables
- Unhandled exceptions
- Check server logs
- Verify
DATABASE_URLis correct - Test database connection manually
- Check Prisma Client is generated
CORS Errors
CORS Errors
Symptoms: Browser console shows CORS errorsSolutions:
- Verify
CORS_ORIGINmatches frontend URL exactly - Include protocol (
https://) - Remove trailing slashes
- Restart backend after changing env vars
Database Migration Failed
Database Migration Failed
Symptoms: Schema out of sync errorsSolutions:
- Check migration SQL for errors
- Verify
DIRECT_URLhas no pooling params - Manually apply migration via SQL client
- Run
npx prisma db pullto sync schema
Frontend Build Fails
Frontend Build Fails
Symptoms: Vercel/Netlify build errorsSolutions:
- Check Node version is 18+
- Verify all dependencies are in
package.json - Clear build cache and retry
- Check for TypeScript errors locally first
Slow API Responses
Slow API Responses
Symptoms: Pages take > 5 seconds to loadSolutions:
- Check database connection pool size
- Increase
connection_limitif needed - Check for N+1 query problems
- Add indexes to frequently queried fields
- Monitor CockroachDB dashboard for slow queries
Deployment Checklist
Use this checklist for each deployment:Pre-Deployment
- Feature freeze on deployment branch
- All tests pass locally
- Database backup created
- Migration plan reviewed
- Environment variables updated
- Team notified of deployment window
During Deployment
- Maintenance mode enabled
- Database migration applied
- Backend deployed and health check passes
- Frontend deployed and loads correctly
- Post-deployment tests pass
Post-Deployment
- Maintenance mode disabled
- Users notified deployment complete
- Monitoring alerts configured
- Deployment documented in changelog
- Team debriefed on any issues
Performance Optimization
Connection Pooling
For optimal performance with 50-100 users:Caching
Consider implementing:- Redis for session storage
- CDN for static assets
- API response caching for reports
Database Indexing
The schema includes optimized indexes. Monitor slow queries in CockroachDB dashboard and add indexes as needed.Next Steps
User Guide
Help users get started with the system
API Reference
API documentation for developers
