Database Migrations: Safe Strategies for Zero-Downtime Deployments
Back to blogs
Published

Database Migrations: Safe Strategies for Zero-Downtime Deployments

E
DevNexus
October 21, 2026
1 min read
4,210 views
0 comments
1 minute read · database

Database migrations are the riskiest part of deployment. These strategies eliminate downtime.

Expand-Contract Pattern

Never rename columns directly. Add new, migrate data, switch code, drop old.

-- Step 1: Add new column (expand)
ALTER TABLE users ADD COLUMN full_name TEXT;

-- Step 2: Backfill
UPDATE users SET full_name = first_name || ' ' || last_name;

-- Step 3: Deploy app using full_name
-- Step 4: Drop old columns (contract)
ALTER TABLE users DROP COLUMN first_name, DROP COLUMN last_name;

Never Lock Tables in Production

-- Safe: non-blocking index creation
CREATE INDEX CONCURRENTLY idx_users_email ON users(email);

Prisma Migrations

npx prisma migrate dev --name add_full_name
npx prisma migrate deploy  # production

Conclusion

Expand-contract and CONCURRENTLY are your two most important tools for safe migrations.