Skip to main content

Claude/ChatGPT Prompt to Plan a Zero-Downtime SQL Schema Migration

Plan a safe, phased schema migration against a live production database with locking analysis, backfill batching, and rollback per step.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt

                                

What this prompt does

This prompt assigns the AI a senior database engineer role and makes it produce a phased, executable plan for migrating a live production schema without downtime. You describe the [change_description], name the [db_engine], and state the table scale as [row_count] rows at [rps] writes per second. It returns a numbered runbook: phased steps (add column, backfill, dual-write, cut over, drop old column), the locking behaviour of each step, a backfill batch size, a rollback path per phase, monitoring signals, and a total duration estimate.

The structure works because it breaks a risky single ALTER into reversible phases that each avoid a long exclusive lock. By tying the backfill batch size to [row_count] and [rps], the prompt sizes the work to your actual write rate instead of guessing. The per-phase rollback path means you can abort safely mid-migration, and the monitoring signals (lock waits, replication lag, error rate) tell you when to. [db_engine] governs the exact locking semantics and tool commands.

When to use it

  • You need to change a hot, large table without taking downtime during business hours.
  • A single ALTER would take a table lock and you need a phased path instead.
  • You want a backfill batch size sized to your real row count and write rate.
  • You need a rollback plan at every phase, not just at the end.
  • You want to know which signals to watch while the migration runs.
  • You are splitting or renaming a column on a table that is too big to lock.

Example output

You get a numbered migration runbook: each phase (add column, backfill, dual-write, cut over, drop old column) with the exact SQL or tool commands, its locking behaviour and how to avoid a long lock, a batch-size recommendation, a safe mid-migration rollback path, the monitoring signals to watch, and a total estimated duration for the full online migration.

Pro tips

  • State [row_count] and [rps] accurately — together they drive the backfill batch size, and a wrong write rate yields batches that lock too long or crawl.
  • Set [db_engine] to the exact version, since locking behaviour for adding columns and indexes differs across engines and releases.
  • Make [change_description] specific, like "split full_name into first_name and last_name," so the dual-write phase is concrete.
  • Backfill in small batches and dual-write through the transition; the cutover should feel boring by the time you reach it.
  • Wire up the monitoring signals before phase one so you can trigger rollback on lock waits or replication lag, not after damage is done.
  • Treat the duration estimate as approximate and run the backfill during low-traffic windows to keep lock contention down.

Frequently Asked Questions

Does the plan really avoid downtime?
It is designed to, by phasing the change so no step takes a long exclusive lock. Whether it stays truly zero-downtime depends on your engine, table size, and write rate, so follow the locking notes and monitoring signals closely rather than assuming it is automatic.
How does it decide the backfill batch size?
It uses `[row_count]` and `[rps]` together to recommend a batch size that keeps each backfill chunk short enough to avoid lock contention. Provide accurate numbers, since an inflated write rate or row count throws the recommendation off in either direction.
Can I roll back partway through?
Yes, the prompt asks for a rollback path at every phase that is safe to trigger mid-migration. That means you can abort after adding the column, during the backfill, or before cutover, which is why the per-phase structure matters for risky changes.
What should I watch while it runs?
The plan lists monitoring signals like lock waits, replication lag, and error rate. Set those dashboards up before you start so you can catch a stalling backfill or rising lag early and trigger the rollback path before it affects users.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Data & SQL Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support