Upgrades & Maintenance
This guide covers upgrading Terragnos Core, handling breaking changes, and performing routine maintenance.
Upgrade Process
Pre-Upgrade Checklist
- Review release notes – Check
docs/releases/for the target version - Backup database – Create a full database backup
- Check compatibility – Verify your configuration is compatible
- Test in staging – Test the upgrade in a non-production environment first
- Schedule maintenance window – Plan for potential downtime
Upgrade Steps
-
Pull new images:
docker compose pull api worker -
Stop services:
docker compose stop api worker -
Run database migrations (if needed):
docker compose --profile setup up db-setup
docker compose --profile setup down -
Start services with new images:
docker compose up -d api worker -
Verify upgrade:
curl http://localhost:3000/v1/health/ready -
Check version:
curl -H "Authorization: Bearer <token>" \
http://localhost:3000/v1/health/ready
# Response includes version information
Zero-Downtime Upgrades
For zero-downtime upgrades:
- Deploy new API instances alongside old ones
- Update load balancer to route traffic to new instances
- Wait for old connections to drain
- Stop old instances
- Upgrade worker instances (can run in parallel with old workers)
Breaking Changes
Breaking changes only occur in major version updates (v1 → v2, v2 → v3, etc.). Minor and patch versions maintain backward compatibility.
Handling Breaking Changes
- Review migration guide – Check release notes for migration steps
- Update API calls – Modify code to use new API contracts
- Update SDKs – Upgrade to compatible SDK versions
- Test thoroughly – Verify all integrations work with new version
- Update configuration – Adjust environment variables if needed
Database Migrations
Automatic Migrations
The db-setup container automatically runs migrations:
docker compose --profile setup up db-setup
Manual Migrations
If you need to run migrations manually:
docker compose exec api node dist/scripts/migrate.js
Migration Safety
- Migrations are idempotent (safe to run multiple times)
- Migrations are backward-compatible within the same major version
- Always backup before running migrations
Maintenance Windows
Recommended Schedule
- Weekly – Review logs and metrics
- Monthly – Database maintenance (VACUUM, ANALYZE)
- Quarterly – Full system review and optimization
- As needed – Security patches and critical updates
Database Maintenance
-- Analyze tables for query optimization
ANALYZE;
-- Vacuum to reclaim space
VACUUM ANALYZE;
-- Check for bloat
SELECT schemaname, tablename,
pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename)) AS size,
n_dead_tup
FROM pg_stat_user_tables
WHERE n_dead_tup > 1000
ORDER BY n_dead_tup DESC;
Rollback Procedure
If an upgrade causes issues:
-
Stop new services:
docker compose stop api worker -
Restore previous images:
# Update docker-compose.yml with previous image tags
docker compose pull api worker -
Start previous version:
docker compose up -d api worker -
Verify rollback:
curl http://localhost:3000/v1/health/ready
Note: Database migrations cannot be automatically rolled back. If migrations were run, you may need to restore from backup.
Release Cadence
- Major versions – Breaking changes, new features (approximately annually)
- Minor versions – New features, backward-compatible (approximately quarterly)
- Patch versions – Bug fixes, security patches (as needed)
Best Practices
- Always backup – Create database backups before upgrades
- Test first – Test upgrades in staging before production
- Read release notes – Review changes and migration guides
- Monitor after upgrade – Watch logs and metrics closely
- Keep images updated – Regularly update for security patches
- Document changes – Keep track of configuration changes
- Plan maintenance – Schedule regular maintenance windows