Skip to main content

Claude/ChatGPT (or Cursor) Prompt to Generate Migration Scripts from a Diff

Turn a schema change diff into safe up/down migration and rollback scripts with batched data migration, safety checks, and seed-data testing.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt
You are a senior database engineer. Turn the schema diff below into safe, runnable migration and rollback scripts, not pseudocode.

Context:
- ORM/migration tool: Prisma
- Environment and scale: production Postgres, ~5M-row orders table
- Schema diff: <paste schema diff>

Deliverables:
1. An up migration and a matching down migration that fully reverses it.
2. Data migration with batching so large tables don't lock or time out.
3. Safety checks: guard against nulls, duplicates, and re-running the migration.
4. An explicit note on whether the change is backwards-compatible for live code.
5. A test run against production-shape seed data with expected before/after counts.
6. A rollback plan covering what to do if the migration fails midway.

Output: the migration file, the rollback file, and the exact commands to run them.

What this prompt does

This prompt makes the AI act as a senior database engineer that converts a schema diff into safe, runnable migration scripts rather than pseudocode. You provide the [diff] to migrate, your [orm] or migration tool, and the [environment] with rough data scale. It then produces six things: a forward (up) migration, a matching down migration that fully reverses it, a batched data migration so large tables don't lock, safety checks against nulls and duplicates and re-runs, a backwards-compatibility note for live code, a seed-data test run with expected counts, and a mid-failure rollback plan.

The structure works because it forces a real down path and batching, which are exactly the parts people skip when a migration looks simple on a small dev database. [orm] decides the migration file format and command syntax, so the output matches your tool instead of generic SQL you would have to translate. [environment] is the key lever: when it says a multi-million-row table, the model leans harder on batching and lock-avoidance, because a migration that is instant on an empty dev database can lock a real table for minutes and stall live traffic. The seed-data test step gives you before and after counts so you can verify the move did what you expected before it ever touches production.

When to use it

  • You are shipping a schema change against a live production database.
  • You need a guaranteed down migration, not just a forward one.
  • A data backfill touches a large table that could lock or time out.
  • You want explicit safety checks against nulls, duplicates, and re-runs.
  • You need to know whether the change is backwards-compatible with running code.
  • You want a rollback plan for a migration that fails halfway through.

Example output

You get the up migration file, the matching down migration, the batched data-migration code, and the exact commands to run them, plus a backwards-compatibility note for live code, a seed-data test with expected before and after row counts, and a step-by-step rollback plan covering a failure midway through. It is formatted as runnable files and commands for your chosen tool, ready to drop into your migrations directory, not a conceptual description you still have to turn into code.

Pro tips

  • Set [environment] with real row counts; that is what triggers proper batching for large tables.
  • Name [orm] exactly so the files use your tool's real migration format and commands.
  • Paste the complete [diff] so the down migration can fully reverse every change.
  • Run the seed-data test against production-shape data, not an empty dev database.
  • Always read the backwards-compatibility note before deploying alongside live code.
  • Verify the down migration actually reverses the up before you trust the rollback plan.

Frequently Asked Questions

Does it generate a real rollback, not just a forward migration?
Yes. A matching down migration that fully reverses the up is a required deliverable, and there is a separate plan for a migration that fails midway. Still verify the down path yourself against a copy, because some operations like dropped columns cannot be perfectly reversed.
Will it handle large tables without locking them?
It produces a batched data migration specifically so large tables don't lock or time out, and it leans harder on this when `[environment]` states a high row count. Batching reduces lock time but does not eliminate it, so test against production-shape data before running it live.
Which ORMs or migration tools does this work with?
It is tool-agnostic; you set `[orm]` to whatever you use, such as Prisma, TypeORM, Rails, or Laravel migrations, and the output adopts that tool's file format and commands. Naming it exactly is what keeps the generated files runnable rather than generic SQL.
Can I trust the backwards-compatibility note for a live deploy?
The note flags whether the schema change is safe for code that is still running the old version, which matters for zero-downtime deploys. Treat it as expert guidance to verify, not a guarantee, since the model only sees the diff and context, not your full application code.
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 Cursor AI Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

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

mejba.13@gmail.com

✓ 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