# Rollback Procedure — ERP Nutzfahrzeuge --- ## Rollback Strategy The rollback strategy depends on the deployment method used. --- ## Coolify Rollback ### Option A: Redeploy Previous Image 1. In Coolify, navigate to the resource 2. Go to **Deployments** tab 3. Find the last known-good deployment 4. Click **Redeploy** on that deployment 5. Wait for health check to pass 6. Verify endpoints: - `GET /api/v1/health` → 200 - `GET /` → 200 ### Option B: Rollback via Git 1. In the repository, identify the last known-good commit: ```bash git log --oneline -10 ``` 2. Revert to the previous commit: ```bash git revert # or git reset --hard git push origin main ``` 3. Trigger a new deployment in Coolify (auto-deploy or manual) 4. Wait for health check to pass --- ## Docker Compose Rollback ### Step 1: Stop Current Deployment ```bash docker-compose down ``` ### Step 2: Revert Code ```bash git checkout ``` ### Step 3: Rebuild and Restart ```bash docker-compose build docker-compose up -d ``` ### Step 4: Verify ```bash curl -s http://localhost:8000/api/v1/health docker-compose logs --tail 50 backend ``` --- ## Database Rollback ### If Alembic migrations are used: ```bash cd backend /opt/venv/bin/python -m alembic downgrade -1 # rollback one revision # or /opt/venv/bin/python -m alembic downgrade # rollback to specific revision ``` ### If no migration tool: - Database schema changes are applied on app startup via SQLAlchemy `create_all` - Rollback requires manual SQL or restoring from a database backup - **Always take a database backup before deployment:** ```bash pg_dump -U erp_user erp_test > backup_$(date +%Y%m%d_%H%M%S).sql ``` ### Restore from backup: ```bash psql -U erp_user erp_test < backup_YYYYMMDD_HHMMSS.sql ``` --- ## Rollback Decision Tree | Situation | Action | |-----------|--------| | App won't start after deploy | Redeploy previous image (Coolify) or `git checkout` + rebuild (Docker) | | Health check fails | Redeploy previous image; check DB connectivity | | Database migration broke schema | `alembic downgrade` or restore from `pg_dump` backup | | Frontend broken | Rebuild frontend from previous commit; redeploy | | Performance regression | Redeploy previous image; investigate in staging | | Security issue found | Rollback immediately; patch in staging; redeploy | --- ## Post-Rollback Verification After any rollback: 1. ✅ Health check passes: `GET /api/v1/health` → 200 `{"status":"ok"}` 2. ✅ Root endpoint: `GET /` → 200 3. ✅ Login works: `POST /api/v1/auth/login` → 200 with valid credentials 4. ✅ No errors in logs: `docker logs --tail 50` 5. ✅ Frontend loads at production URL 6. ✅ Database queries return expected data --- ## Emergency Rollback (Quick) If the deployment is causing immediate issues: ```bash # Coolify: use the Redeploy button on the last good deployment # Docker Compose: docker-compose down git checkout docker-compose build && docker-compose up -d curl -s http://localhost:8000/api/v1/health ``` **Time to rollback:** < 5 minutes (if image is cached) or < 15 minutes (if rebuild needed).