Skip to main content

Claude Prompt to Test Database Migrations and Validate Rollbacks

Test migrations for safety: validate rollbacks, check for data loss, simulate production-scale timing, and analyze locks for zero-downtime.

Vul de plaatshouders in

Edit the values, then copy your finished prompt.

Jouw Prompt
prompt.txt

                                

What this prompt does

This prompt creates a migration testing framework for a [framework] application on [database], focused on the [migrations] you list. It validates that up migrations produce the expected schema, that down migrations fully reverse them, and that no data is lost in either direction — the checks that keep a bad migration from reaching production. It also confirms that seeders still run and that foreign-key constraints hold after the change.

It works because a migration failure on a live database is one of the scariest failure modes, so it tests timing and locking before anything touches prod. It simulates each migration on a table with [row_count] rows to measure execution time, analyses which migrations acquire exclusive locks and estimates downtime, and proposes zero-downtime patterns for your [dangerous_migrations]. It also verifies index effectiveness with EXPLAIN on key queries and adds a CI stage that runs against a clone of the production schema, so problems surface in the pipeline rather than on deploy night.

When to use it

  • You're about to run a risky migration on a live [database] and want it tested first
  • You need to confirm down migrations actually reverse the up migrations
  • Large tables mean you must measure timing and locks before production
  • Specific [dangerous_migrations] (column rename, NOT NULL backfill) need zero-downtime patterns
  • You want to verify seeders and foreign keys still hold after a migration
  • You want a CI stage that runs migrations against a clone of the production schema

Example output

You get a testing framework: up-migration schema validation, down-migration reversal checks, data-integrity verification for each of your [migrations], a large-table simulation on [row_count] rows with execution timing, a lock analysis estimating downtime, zero-downtime patterns for [dangerous_migrations], seeder-compatibility checks, foreign-key validation, index-effectiveness checks via EXPLAIN, a CI stage running against a production-schema clone, plus test helpers and a migration safety checklist.

Pro tips

  • List your real [migrations] so the framework tests the actual schema changes you're shipping, not generic examples
  • Set [row_count] to mirror your largest affected table; a migration that's instant on test data can lock a million-row table for minutes
  • Always test the down migration too — a rollback that doesn't fully reverse changes is as dangerous as a broken up migration
  • Flag the truly risky ones in [dangerous_migrations] (renames, NOT NULL with backfill) so the AI applies zero-downtime patterns like expand-then-contract
  • Run the CI stage against a clone of the production schema, since structure, indexes, and data volume differ from a fresh test database
  • Check index effectiveness with EXPLAIN after the migration, so a new index actually gets used by the queries it was meant to speed up
  • Use the lock analysis to schedule risky migrations for low-traffic windows when downtime can't be fully avoided

Frequently Asked Questions

Does this test that rollbacks actually work?
Yes, down-migration validation is a core part of it: the framework checks that each rollback fully reverses the corresponding up migration and that no data is lost in the process. A rollback that only partially reverses changes is as dangerous as a broken forward migration.
How does it estimate production downtime?
It simulates each migration against a table with `[row_count]` rows to measure execution time, then analyses which migrations acquire exclusive locks. From that it estimates downtime, since a change that is instant on test data can lock a large table for minutes in production.
Can it handle zero-downtime migrations?
Yes, for the `[dangerous_migrations]` you flag, such as a column rename or adding a NOT NULL constraint with a backfill, it proposes zero-downtime patterns like expand-then-contract. These let you deploy schema changes in stages without taking the application offline.
Why run migration tests against a production-schema clone?
Because a fresh test database often differs from production in structure, indexes, and data volume. Running the CI stage against a clone of the production schema surfaces lock and timing issues that a clean test setup would hide, giving you a realistic picture before deploying.
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.

Meer in Testing & QA Automation 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