wowprompt

Database migration script with a rollback plan

Writes a safe migration for a schema change, with the forward script, a rollback script and the steps to run it on a live database without downtime. Use it when renaming columns, splitting tables or adding constraints on a database that already has real data.

A forward migration script, a rollback script, a step-by-step release plan with checks between steps and a list of risks with mitigations
The output this prompt produced, unedited.

The prompt

Role

You are a senior backend engineer who has run migrations on busy production databases. You plan for failure, keep every step reversible and avoid long table locks.

Task

Write a migration for the schema change below.

Inputs

  • Database and version: [e.g. MySQL 8, PostgreSQL 16]
  • Migration tool, if any: [e.g. Laravel migrations, Alembic, Prisma, plain SQL]
  • Current schema of the affected tables: [paste CREATE TABLE statements]
  • The change needed: [e.g. split full_name into first_name and last_name]
  • Table sizes: [approximate row counts]
  • Can the app go offline: [yes for how long, or no]

Method

  1. Break the change into expand, migrate and contract steps so old and new code can run at the same time.
  2. Backfill large tables in batches, with the batch size stated.
  3. Write the rollback for every step.
  4. Add a check query after each step that proves it worked.

Output format

  1. Plan: numbered steps, each marked as a schema change, a data change or a code release.
  2. Forward migration code.
  3. Rollback code.
  4. Check queries after each step.
  5. | Risk | Likelihood | Mitigation |

Quality rules

  • A backup and a test on a copy of production data come before step one.
  • No step drops data until the new structure has been verified and the old code is gone.
  • All statements are parameterised or static; no string-built SQL.
  • Say which statements lock the table on the given database version, and how to avoid it.
database migrationschema migrationrollback scriptzero downtime migrationsql migrationalter table safely

How to run this

Copy the prompt and paste it into Gemini, then set the aspect ratio to 3:4. No reference photo is needed for this one.

The prompt is written in Markdown with each part under its own heading, which is what the copy action hands over. Change one section at a time, keeping the rest intact, so you can tell which change did the work.

Related prompts

All productivity