How would you implement version control for database schema changes?
Instruction: Describe the strategies and tools you would use to manage and track changes to a database schema over time.
Updated
Official answer
Keep ordered migration files with application code, review them, and record which migrations each environment has applied. Use the existing migration framework and its history/checksum protections. Once applied, correct a migration with a new migration rather than silently editing its historical meaning.
Test both a fresh install and an upgrade from realistic existing data. Check constraints, data conversions, application compatibility, lock duration, table rewrites and failure recovery. Detect manual schema drift rather than assuming every environment matches merely because it has the same code checkout.
For a breaking change, use an expand-and-contract sequence: introduce the compatible new structure, backfill with resumable bounded work, deploy readers/writers that handle the transition, validate, then remove the obsolete structure after old clients are gone. Define the source of truth during any dual-write period.
Coordinate deployment so only the intended migration runner acts. DDL transaction behavior varies by engine and operation; do not assume every failed migration rolls back. A reverse migration cannot recover data dropped by a destructive change. Prepare a tested forward fix or restore strategy, monitor the rollout, and retain evidence of the applied version and validation.
Related Questions
-
medium
-
hard
-
hard
-
hard