🚀Safe Schema Deployment to DigitalOcean - Zero Data Loss Guide

📋 Pre-Deployment Checklist

1. Backup Strategy

# 1.1. Create production database backup
# Connect to your DO database and create a backup
pg_dump "postgresql://doadmin:AVNS_rLjrCHHSkP066lMnh8q@riswis-db-do-user-21375598-0.g.db.ondigitalocean.com:25060/defaultdb?sslmode=require" > riswis-backup-$(date +%Y%m%d_%H%M%S).sql

# 1.2. Download and store backup safely
# Store in multiple locations (local, cloud storage, etc.)

2. Environment Verification

# 2.1. Check local database status
cd backend
npx prisma migrate status

# 2.2. Generate migration if needed (if you have schema changes)
npx prisma migrate dev --name add_marketing_features --create-only

# 2.3. Review generated migration files
ls -la prisma/migrations/

3. Testing Strategy

# 3.1. Test migrations on local copy of production data
# 3.2. Verify application functionality after migration
# 3.3. Test rollback procedures

🚀 Deployment Process

Step 1: Prepare Migration Command

# Add to package.json scripts in backend:
"deploy:migrate": "npx prisma migrate deploy && npx prisma generate"

Step 2: Update App Spec for Migration

Create a one-time job for migration:

# Add to riswis-app-spec.yaml under services:
- name: migration-job
  github:
    repo: Linxford/RisWis
    branch: msl-production
  source_dir: backend
  environment_slug: node-js
  build_command: npm install --legacy-peer-deps --force
  run_command: npm run deploy:migrate
  kind: JOB
  envs:
    - key: DATABASE_URL
      value: "postgresql://doadmin:AVNS_rLjrCHHSkP066lMnh8q@riswis-db-do-user-21375598-0.g.db.ondigitalocean.com:25060/defaultdb?sslmode=require"
      type: SECRET

Step 3: Deploy with Migration

# 1. Push schema changes to msl-production branch
git add .
git commit -m "feat: add marketing campaign schema and features"
git push origin msl-production

# 2. Deploy via DigitalOcean CLI or Dashboard
doctl apps create --spec riswis-app-spec.yaml
# OR update existing app
doctl apps update [APP_ID] --spec riswis-app-spec.yaml

Option B: Manual Migration (if auto-deploy fails)

Step 1: Connect to Production Database

# Using psql
psql "postgresql://doadmin:AVNS_rLjrCHHSkP066lMnh8q@riswis-db-do-user-21375598-0.g.db.ondigitalocean.com:25060/defaultdb?sslmode=require"

# Or using DO CLI
doctl databases connection [DATABASE_ID]

Step 2: Run Migrations Manually

# Set production DATABASE_URL
export DATABASE_URL="postgresql://doadmin:AVNS_rLjrCHHSkP066lMnh8q@riswis-db-do-user-21375598-0.g.db.ondigitalocean.com:25060/defaultdb?sslmode=require"

# Deploy migrations
npx prisma migrate deploy

# Verify migration status
npx prisma migrate status

# Generate Prisma client for production
npx prisma generate

🔍 Post-Deployment Verification

1. Database Schema Verification

-- Connect to production database and verify tables exist
\dt
SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name LIKE 'MarketingCampaign';
SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name LIKE 'MarketingLead';
SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name LIKE 'CampaignAnalytics';

2. Application Health Checks

# Check backend health
curl https://api.modernsavingsandloans.com/api/health

# Check marketing endpoints
curl https://api.modernsavingsandloans.com/api/marketing/health

# Check frontend
curl https://ibank.modernsavingsandloans.com/api/health

3. Feature Testing

  • ✅ Login functionality

  • ✅ Marketing dashboard loads

  • ✅ Campaign creation works

  • ✅ Campaign editing works

  • ✅ Campaign deletion works

  • ✅ Export functionality works

🔄 Rollback Plan (if something goes wrong)

Emergency Rollback Steps

# 1. Stop the application
doctl apps list
doctl apps update [APP_ID] --spec rollback-spec.yaml

# 2. Restore database from backup
pg_restore -d "postgresql://doadmin:AVNS_rLjrCHHSkP066lMnh8q@riswis-db-do-user-21375598-0.g.db.ondigitalocean.com:25060/defaultdb?sslmode=require" riswis-backup-[DATE].sql

# 3. Deploy previous version
git checkout [PREVIOUS_COMMIT]
git push origin msl-production --force

📊 Monitoring During Deployment

Key Metrics to Watch

  • Application uptime

  • Database connection status

  • Error rates in logs

  • Response times

  • User session continuity

Log Monitoring

# Check application logs
doctl apps logs [APP_ID] --component backend --follow

# Check for errors
doctl apps logs [APP_ID] --component backend | grep -i error

🔧 Migration-Specific Considerations

For Marketing Tables

-- After migration, verify marketing tables
SELECT COUNT(*) FROM "MarketingCampaign";
SELECT COUNT(*) FROM "MarketingLead";
SELECT COUNT(*) FROM "CampaignAnalytics";

-- Check if enum values are correct
SELECT unnest(enum_range(NULL::enum_CampaignStatus));
SELECT unnest(enum_range(NULL::enum_CampaignType));

Performance Considerations

  • Marketing tables have proper indexes

  • Foreign key constraints are in place

  • Default values are set correctly

🚨 Emergency Contacts & Resources

  • DigitalOcean Support: Available via dashboard

  • Database Backup Location: [Specify backup storage location]

  • Rollback Time Estimate: 15-30 minutes

  • Downtime Window: Aim for < 5 minutes

📝 Post-Deployment Tasks

  1. ✅ Update documentation

  2. ✅ Notify team of successful deployment

  3. ✅ Schedule backup verification

  4. ✅ Monitor for 24 hours

  5. ✅ Update deployment logs


Last Updated: $(date) Version: 1.0 Tested On: Development/Staging ✅ | Production ⏳

Last updated