Migration Safety Guide¶
Pre-deployment checklist and rollback procedures for FilaOps database migrations.
Pre-Deployment Checklist¶
Before Running Migrations¶
-
Backup the database
-
Verify the current migration state
-
Review pending migrations
-
Test migrations against a copy
-
Check for destructive operations — Review migration files for:
op.drop_table()orop.drop_column()op.alter_column()with type changes- Any raw SQL
op.execute()statements
During Deployment¶
- Put the application in maintenance mode (stop accepting new requests)
- Run the migration:
alembic upgrade head - Verify the migration applied:
alembic current - Start the application and verify the health check:
curl http://localhost:8000/health - Spot-check critical workflows (login, create order, view dashboard)
Rollback Procedures¶
Downgrading Migrations¶
# Roll back one migration
alembic downgrade -1
# Roll back to a specific revision
alembic downgrade <revision_id>
Full Database Restore¶
If a migration causes data loss or corruption:
# Stop the application
docker compose stop backend
# Restore from backup
pg_restore -d filaops --clean filaops_backup_YYYYMMDD_HHMMSS.dump
# Restart
docker compose start backend
Docker Compose Rollback¶
# Stop current version
docker compose down
# Check out the previous release tag
git checkout v3.0.1
# Rebuild and restart
docker compose up -d --build
Version Verification¶
After deployment, verify all version references match:
| Location | Command |
|---|---|
| Backend VERSION file | cat backend/VERSION |
| Settings runtime | curl http://localhost:8000/health \| jq .version |
| Frontend | Check the browser console or about page |
| Alembic head | cd backend && alembic current |
Backup Schedule Recommendations¶
| Environment | Frequency | Retention |
|---|---|---|
| Production | Daily (automated) | 30 days |
| Staging | Before each deployment | 7 days |
| Development | As needed | N/A |
For automated backups, use pg_dump in a cron job or Docker healthcheck script.