Exercise: The Data Rollback
- Pre-Migration Drill: Verify your PITR status in CNPG. Capture the current timestamp.
- Execute Migration: Deploy a test migration that intentionally corrupts a “dummy” table.
- Verify Failure: Identify the data corruption and the resulting application error.
- Code Revert: Revert the migration commit in Git and let Flux reconcile the previous version.
- Data Restore: Trigger a PITR restore to the timestamp captured in step 1.
- Final Verify: Prove that the database schema and data have returned to their known-good state.
Core Exercises (Required)
- Status Check: Use
kubectl get clusters.postgresql.cnpg.io -n developto check the health and backup status of your database. - Schema Audit: Inspect the migration history table in your database and identify the last successful and failed runs.
- Expand-Contract Review: Analyze a proposed breaking change and rewrite it using the Expand-Contract pattern.
Challenge Exercise (Optional)
Full Expand/Contract Migration Cycle: Execute a full expand/contract migration cycle on a test CNPG database: add a new column with default, deploy application code that uses it, then remove the old column. Verify rollback capability at each phase.
Done When
You have completed this chapter when:
- You can explain why code rollbacks are insufficient for stateful changes.
- You have successfully executed an atomic code + data rollback.
- You can demonstrate a Point-in-Time Recovery (PITR) using CNPG.
- You understand and can apply the Expand-Contract migration pattern.
Knowledge Check
Before finishing this chapter, complete the Quiz to verify your understanding of the guardrail principles.