# Expand → Migrate → Contract: Shipping Schema Changes Without Downtime
<!--
ref: @knowledge/protocols/expand-migrate-contract-schema-changes
type: protocol
tags: [database, schema migration, downtime, production readiness, best practices]
triggers: [schema change deployment, live product updates, database migration errors, rollback requirements]
trigger_prompt: When a developer needs to change the database schema of a live application without causing downtime or data loss.
version: 2
updated_at: 2026-10-18T05:41:39.917Z
-->

Ship the schema without the code and it breaks; ship the code without the schema and it breaks. Expand-migrate-contract dissolves the ordering problem by making every intermediate state independently valid.

*Synthesized from Sean Kochel, "Turning a Vibe-Coded Demo Into a Real Product (11 Things)" — the practice he singles out as the most valuable on his production-readiness list.*

Changing a schema on a live product is a deadlock the first time you hit it: neither deploy order is safe. Deploy the migration first and the running code meets columns it doesn't know about. Deploy the code first and it queries columns that don't exist. The resolution is to stop treating it as one change.

## The sequence

**1. Expand.** Add the new columns; ship the migration alone. Nothing reads them yet, so nothing can break. The database is now a strict superset of what the running code expects — additive, and safe by construction.

**2. Backfill.** Populate the new columns from the old ones. Still nothing reads them. This step is re-runnable and abortable: if the backfill is wrong, fix it and run it again, with no user-visible surface.

**3. Cut over.** Ship the code that reads the expanded schema. The old columns stay physically in place — merely unread. If the new code is wrong, the previous shape is intact behind it and rollback is a code deploy, not a data recovery.

**4. Contract.** Only after the new version is verified in production do you drop the old schema. This is the one irreversible step, and it is deliberately last and deliberately separate.

## Why it holds

Each phase leaves the system in a deployable, working state. That is the whole property. It's what makes the sequence safe to *interrupt* — you can stop after any step and ship other work — safe to roll back, and safe to hand to an agent that may get one step wrong without taking production down with it.

## Precondition

Run schema changes through a **migration system** — version control for your schema, rollable forward and back — never by hand-editing tables. Without one, "contract" has no undo and the safety property collapses.

*Models default to skipping this entirely; see `gates-vs-nets-production-readiness` for the broader pattern of database work AI agents get wrong by default.*

---

*Related: `@integrations/notion-databases` · `@knowledge/protocols/agent-context-file-hygiene`*

---

*You're reading a protocol on [protocol.supply](https://protocol.supply) — hosted, searchable knowledge for AI agents. Think Agent Skills, as an API: bootstrap once (`curl -sL https://api.protocol.supply/bootstrap`), search (`/search?q=…`), fetch (`/@repo/slug`).*

*Any skill can become a protocol, and any protocol installs as a local skill — tell your agent "install this as a skill" or see [`@protocol/protocol-to-skill`](https://api.protocol.supply/@protocol/protocol-to-skill).*