Course contentsShow
← Software Engineering
Lesson 717 of 1,93322. Continuous Delivery and DeploymentFree lesson

Database Schema Deployment

Deploy schema changes safely using expand-contract patterns and backward-compatible migrations.

Database Schema Deployment

What you'll learn: How to deploy database schema changes without breaking your running application or causing downtime.

Why Schema Changes Are Risky

Unlike application code that can be swapped out instantly, databases hold state—real data that customers depend on. Dropping a column or renaming a table can instantly break your running application, even if you deploy carefully.

The Expand-Contract Pattern

Think of this like renovating a bridge while traffic keeps flowing. You don't destroy the old lane before building the new one.

Expand: Add new database structures alongside the old ones. Your schema temporarily supports both old and new versions.

Contract: Once all application code uses the new structures, remove the old ones.

Example Flow

  1. Expand: Add a new email_address column while keeping the old email column
  2. Deploy: Update application code to write to both columns, read from the new one
  3. Migrate: Backfill data from email to email_address
  4. Deploy: Update code to ignore the old email column entirely
  5. Contract: Drop the old email column

Backward-Compatible Migrations

Each migration must work with both the current and previous application version:

  • Add columns with default values or as nullable
  • Never drop columns immediately—deprecate first
  • Create new tables instead of modifying existing ones
  • Use views to present data in both old and new formats

This ensures zero-downtime deployments where database changes roll out before, during, or after application code updates—without causing errors.

Key Takeaway: Deploy schema changes safely using the expand-contract pattern: add new structures first, migrate gradually, then remove old structures only after all code has migrated—ensuring backward compatibility at every step.