CLAUDE LABJP
FORK — Claude Code 2.1.212 changes what /fork does: it copies your conversation into a new background session with its own row in claude agents, so you can keep working. The old in-session subagent is now /subtaskLIMITS — WebSearch calls are now capped at 200 per session by default, and subagent spawns get the same 200 ceiling, so a runaway search or delegation loop stops on its ownMCPBG — MCP tool calls running past two minutes now move to the background automatically, keeping the session usable. Tune the threshold with CLAUDE_CODE_MCP_AUTO_BACKGROUND_MSPLANFIX — Fixed plan mode auto-running file-modifying Bash commands such as touch and rm without a permission prompt or an SDK canUseTool callbackSONNET5 — Claude Sonnet 5 is running on introductory pricing of $2 per million input tokens and $10 per million output. After August 31 it moves to $3 and $15IPO — Bankers are reportedly lining up investor meetings for Anthropic ahead of a possible public listing as soon as OctoberFORK — Claude Code 2.1.212 changes what /fork does: it copies your conversation into a new background session with its own row in claude agents, so you can keep working. The old in-session subagent is now /subtaskLIMITS — WebSearch calls are now capped at 200 per session by default, and subagent spawns get the same 200 ceiling, so a runaway search or delegation loop stops on its ownMCPBG — MCP tool calls running past two minutes now move to the background automatically, keeping the session usable. Tune the threshold with CLAUDE_CODE_MCP_AUTO_BACKGROUND_MSPLANFIX — Fixed plan mode auto-running file-modifying Bash commands such as touch and rm without a permission prompt or an SDK canUseTool callbackSONNET5 — Claude Sonnet 5 is running on introductory pricing of $2 per million input tokens and $10 per million output. After August 31 it moves to $3 and $15IPO — Bankers are reportedly lining up investor meetings for Anthropic ahead of a possible public listing as soon as October
Articles/Claude Code
Claude Code/2026-05-02Advanced

Designing Zero-Downtime Database Migrations with Claude Code: A Production Operations Guide

A production guide to designing zero-downtime database migrations with Claude Code. Covers Expand-Contract, NOT NULL additions, renames, backfills, and subagent reviews — practical patterns that survive real production traffic.

claude-code129database2migration6production111postgresqladvanced11

Premium Article

Database migrations are the quiet kind of work most days, but on the rare day they break in production, they break everything. I once shipped an ALTER TABLE ... ADD COLUMN ... NOT NULL at 2 AM on a PostgreSQL instance that hadn't yet upgraded past version 10, and the full-table rewrite locked out our API for thirty minutes. Application retries amplified the lock contention, and by the time I rolled back, dashboards were lit up red. I've never forgotten the sweat of that night.

The hard part is that the danger of a migration isn't visible from reading the SQL alone. Whether one line of DDL takes a millisecond or scans every row depends entirely on the database engine, the version, and the table size. Claude Code is, in my experience, exceptionally good at spotting these invisible landmines and rewriting migrations into safer multi-step shapes. This guide brings together the patterns I now use to evolve schemas without taking the system offline, paired with how I drive Claude Code through each step.

Why Migrations Take Down Production

In my own incident reviews, the migrations that take a system down almost always fall into one of three categories. The first is running long-locking DDL directly against production. Statements like ALTER TABLE ... ADD COLUMN ... NOT NULL DEFAULT 'foo' are instant on PostgreSQL 11 and later, but they trigger a full table rewrite on older versions and on certain managed services. On a hundred-million-row table, that translates to minutes of locked tables and a flood of timeouts.

The second category is shipping the application code and the schema in the wrong order. If the new schema reaches production while old replicas still serve traffic, the old code starts referencing columns that no longer exist and returns 500s. Reverse the order and the new code can't find columns it expects. There's no path through this except careful sequencing.

The third category is launching a migration without a rollback plan. The moment a DROP COLUMN lands, the data is gone. By the time you realize something downstream broke, restoring from backup means losing every write that happened in between. The Expand-Contract pattern exists precisely to make these three categories impossible.

Three Principles That Make Zero Downtime Possible

Expand-Contract works because it enforces three principles. The first principle is that you always pass through a state where both the old code and the new code can run. You create a window — sometimes hours, sometimes weeks — where the application can read and write either shape, and you advance the deploys through that window step by step.

The second principle is that you only run DDL that completes in a fraction of a second on production. Anything longer gets decomposed into smaller DDL, or routed through online migration tools like pg_repack or gh-ost. If a single statement might lock a hot table for more than about a second, it doesn't go to production as-is.

The third principle is that every migration has a real reverse direction, and the reverse direction doesn't lose data. You write down migrations that you'd actually run if production caught fire, not toy ones that satisfy a linter.

I make these explicit to Claude Code by keeping a section in my project's CLAUDE.md like this:

# Migration Operations Rules
 
## Mandatory
- DDL applied to production must complete in under 1 second
- New columns are added as NULLable, then promoted to NOT NULL in a later migration
- Column drops follow: remove all code references → deploy → DROP COLUMN
- Renames follow: add new column → dual-write → switch reads → drop old column
- Every migration ships with a real, tested down migration
 
## Required Review Items
- Estimated affected row count (verified with EXPLAIN or COUNT)
- Predicted lock time (measured against a realistic test database)
- Compatibility with the previous deployment (does old code keep running?)

Once that's in place, Claude Code naturally generates migrations that respect the rules instead of taking the dangerous shortcut.

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
If you've ever broken up a sweat watching a production migration stall mid-deploy, you'll learn the Expand-Contract patterns to ship without downtime starting today
You'll get concrete SQL and code for the riskiest changes — NOT NULL additions, column renames, type changes — broken into safe five-step deploys
You'll learn how to delegate migration reviews to a Claude Code subagent so production landmines get caught before they reach a real database
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

Claude Code2026-07-09
Is the Draft That Passed the Gate the Same One You Published?
In unattended pipelines, the file your quality gate inspected and the file you actually publish can quietly diverge. Here is a digest-bound gate receipt design, with working code and measured results from 180 days of running it.
Claude Code2026-07-03
Five Minutes of Silence, and Something Retries on Your Behalf — Rethinking Retry Ownership After the Streaming Idle Watchdog Became a Default
Claude Code's streaming idle watchdog is now on by default, quietly adding another retrying layer to your stack. This article inventories the four layers (SDK, wrapper, watchdog, scheduler), computes worst-case attempt amplification, and shows how to collapse retry ownership into a single layer.
Claude Code2026-05-05
7 Design Principles for Production-Grade Autonomous Agents with Claude Code SDK
Building a Claude Code SDK agent that works is easy. Building one that keeps working in production is hard. Here are the 7 design principles I extracted from running content automation systems at scale.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →