Expand and contract database migrations: safe deployment with live writers
Use expand and contract migrations to keep old and new application versions compatible while backfilling retained data and verifying every writer before schema contraction.
5 min read

In this article
A release renames a column while old queue workers still read it. The new web application works, but background jobs fail immediately. Rolling back code does not automatically restore the removed schema or data.
Expand and contract migrations keep old and new versions compatible while the application changes its data contract. The difficult part is coordinating live writers and long-lived consumers, not just adding an extra migration file.
Our Laravel production checklist covers release gates. This guide uses a hypothetical MySQL-backed field transition and distinguishes Prisma ORM 7 guidance from newer version-specific tooling.

Step 1: Inventory every schema consumer before expand and contract
List web instances, queue workers, scheduled tasks, reports, exports and operational scripts. Include queued payloads created before the rollout and any prior release that remains eligible for rollback.
For illustration, suppose an orders table moves from delivery_note to fulfillment_note with unchanged business meaning. If the meaning also changes, define the transformation explicitly rather than assuming a field copy is correct.
| Consumer | Compatibility evidence |
|---|---|
| Old web release | Continues using the retained old field |
| Transitional release | Coordinates both representations |
| Background workers | Understand retained payload and schema versions |
| Reports and exports | Use the intended field and format |
| Rollback artifact | Remains compatible with the expanded schema |
One successful new request does not prove all consumers are compatible.
Step 2: Expand without removing the old contract
Add a compatible new field through the existing reviewed migration owner. For an existing Laravel migration, an expansion fragment might be:
Schema::table('orders', function (Blueprint $table): void {
$table->string('fulfillment_note', 255)->nullable();
});
The fragment assumes the existing Schema and Blueprint imports and a reviewed orders schema. It is not an instruction to run DDL on retained data without rehearsal.
Review the exact generated database operation. MySQL online DDL support depends on the operation and table conditions; online does not mean there are no metadata locks or resource costs.
Do not promise an instant operation merely because a framework migration looks short. Rehearse its lock behavior, disk headroom and failure path using a representative isolated copy.
Step 3: Establish the live-writer contract
Before backfilling, decide how every writer keeps old and new representations consistent. Transitional application code can write both atomically where that fits the data model, but old code still writing only the old field needs a deliberate compatibility plan.
Options include completing the compatible-writer rollout first, a reviewed database mechanism or a maintenance window for the relevant writes. Each has operating costs; choose explicitly rather than pretending a backfill compensates for unknown writers.
Preserve authorization and validation in the existing write owner. A migration helper should not become an unrestricted second application API.

Step 4: Backfill in resumable bounded batches
Use a stable cursor, a defined initial high-water boundary and durable checkpoints. Choose a measured batch size and pause condition based on query latency, replication behavior and operating headroom.
Protect against concurrent changes. A read followed by an unconditional update can overwrite a newer application value. Use the reviewed transaction, row version or conditional-write contract appropriate to the schema.
Define how legitimate null values differ from unprocessed rows. A nullable field alone may not be a sufficient migration-progress marker.
load migration checkpoint
select the next bounded primary-key range
apply the reviewed concurrency-safe transformation
commit data changes and checkpoint appropriately
observe impact before the next range
resume safely after interruption
This is a protocol outline. The application must implement its atomicity and conflict behavior; an informal loop does not prove safe backfill semantics.
Step 5: Verify data and switch reads deliberately
Check mismatches and business invariants before preferring the new field. For the hypothetical same-meaning fields, an authorized MySQL read can inspect a bounded ID range:
SELECT id
FROM orders
WHERE id > 1000 AND id <= 2000
AND NOT (delivery_note <=> fulfillment_note)
ORDER BY id
LIMIT 20;
The null-safe comparison fits this specific copy contract. The IDs are examples, and the output limit is not a complete proof that every row is correct. Use reviewed ranges and a complete verification plan with known cost.
Switch reads only when the acceptance contract is met. Monitor outcomes and retain the old compatible representation through the intended reversal window.
Step 6: Retire old consumers before contraction
Confirm old web and worker processes are gone, retained queued payloads remain compatible and reports no longer depend on the old field. Include external consumers if the schema change affects an API or exported format.
| Contraction gate | Evidence required |
|---|---|
| Data correctness | Backfill and invariant verification complete |
| Reader retirement | No supported reader needs the old shape |
| Writer retirement | No live writer updates only the old shape |
| Rollback boundary | Intended prior release no longer requires it |
| Retention decision | Removed data and recovery consequences reviewed |
Do not remove the old column in the same casual step that introduces the new one. Contraction changes the recovery contract and needs its own reviewed migration.

Step 7: Rehearse failure and phase-specific reversal
Exercise interrupted batches, writer conflicts and old queued payloads in isolated staging. Confirm the checkpoint resumes safely and the application does not present partially transformed data as complete.
Before contraction, code reversal may remain possible because both shapes survive. After destructive contraction, restoration or a forward repair can be required; a down migration cannot recreate lost business values automatically.
Our audit-log design guide explains accountable mutations. For safe schema transitions fitted to your application, discuss the project with Cloudsoft Zone.
Featured image: Cloudsoft Zone technical layout with mysql artwork by Oracle Corporation; vectorized by VulcanSphere (Public domain (text logo); trademark retained). Product mark resized proportionally for identification; no endorsement implied. Layout: CC BY-SA 4.0.
Frequently asked questions
Does adding a column guarantee zero downtime?
No. The exact DDL operation, database version, table state and metadata locks affect behavior. Rehearse the operation and its waiting or interruption cost.
Can a backfill safely copy values while old code keeps writing?
Only with a deliberate live-writer consistency contract and concurrency safeguards. Otherwise a backfill can miss later writes or overwrite newer values.
When is it safe to remove the old column?
After all readers and writers, queued payloads, operational tools and the intended rollback path have retired it, with verification and a reviewed data-retention decision.
Sources
- Prisma7 expand-and-contract pattern — Prisma
- MySQL8.4 online DDL operations — MySQL
- Online DDL limitations — MySQL
- Metadata locking — MySQL
- Laravel reviewed migrations — Laravel
Read next

TutorialDevOps5 min read
Prevent duplicate queue jobs: durable admission and payment webhook recovery
Prevent duplicate queue jobs with durable operation identity, atomic admission and verified recovery rather than relying only on queue IDs, locks or a successful webhook response.
New tools, once a week
One short email listing what joined the directory.
Comments
No comments yet. Be the first to join the conversation.
Leave a comment
Every comment is read by a moderator before it appears. Your email address is never published; it is used only to contact you about this comment.
More from Cloudsoft Zone

ComparisonDevOps5 min read
MySQL vs PostgreSQL for SaaS hosting: operational differences small teams should evaluate
Compare MySQL vs PostgreSQL through maintenance, connections, recovery, migration compatibility and team experience rather than unsupported universal performance rankings.
By Nilesh Kushvaha

TutorialDevOps5 min read
MySQL production configuration for Laravel applications: a safe operating baseline
Review MySQL production configuration for Laravel using measured memory and connection budgets, explicit durability, protected access and verified restore procedures.
By Nilesh Kushvaha

Troubleshooting guideDevOps5 min read
Database connection pool exhaustion: causes, symptoms and safe fixes
Diagnose database connection pool exhaustion by separating application acquisition waits, server limits, leaked clients and slow transactions before increasing capacity.
By Nilesh Kushvaha