Database Migrations Without Downtime
Database migrations are the scariest part of deployments. Get them wrong and you’re looking at downtime, data loss, or a 3 AM incident call. Here’s how to migrate safely. The Problem Naive migrations cause problems: 1 2 3 4 5 6 -- This locks the entire table ALTER TABLE users ADD COLUMN phone VARCHAR(20) NOT NULL; -- 10 million rows, exclusive lock held for minutes -- Application queries queue up -- Users see errors Safe Migration Patterns Adding Columns Bad: Adding NOT NULL column without default ...