# Rollback Procedure ## Prerequisites - Access to the VPS with docker compose permissions - Database backup taken before the upgrade (see step 1) ## Procedure ### 1. Backup database (ALWAYS before upgrade) ```bash docker compose exec postgres pg_dump -U erp erp > backup_$(date +%Y%m%d_%H%M%S).sql ``` ### 2. Identify current and previous image ```bash docker compose images backend # Current: ghcr.io/tarulab/keluargamart-backend: # Previous: check GHCR tags or docker compose images output ``` ### 3. Roll back application ```bash # Pull the previous SHA tag docker pull ghcr.io/tarulab/keluargamart-backend: # Update the image reference in docker-compose.yml or .env # then restart docker compose up -d backend ``` ### 4. Roll back database (ONLY if schema-incompatible) ```bash # Migrations are forward-only. To roll back schema: docker compose exec postgres psql -U erp erp < backup_YYYYMMDD_HHMMSS.sql ``` ### 5. Verify ```bash curl -f http://localhost:3004/ready curl -f http://localhost:3004/health ``` ## Key Rules - ALWAYS backup before upgrade - Migrations are forward-only (Atlas); never edit applied migrations - AUTO_MIGRATE only adds columns/tables/indexes — never drops or truncates - Frontend images are stateless — rollback is just re-pulling the old tag