Entity Framework Core Interview Question #98

How should potentially destructive schema changes be deployed?

Migrations, Database Schema & Data Management Mid-Level Intermediate

Quick Interview Answer

Destructive changes such as dropping columns, shrinking data types, or changing constraints should be planned around existing data and application compatibility.

Detailed Explanation

Destructive changes such as dropping columns, shrinking data types, or changing constraints should be planned around existing data and application compatibility.

A safer production strategy often uses multiple releases: first add the new schema in a backward-compatible way, update application code and migrate data, verify the new path, and only later remove obsolete schema.

Backups, tested rollback or recovery procedures, deployment monitoring, and an understanding of locking and execution time are important for high-value databases.

Code Example

// Example expand-and-contract strategy:
//
// Release 1: Add NewColumn (nullable)
// Release 2: Write/read new structure and backfill data
// Release 3: Stop using OldColumn
// Later:    Drop OldColumn after verification