It is Thursday evening. The release window opens at nine tomorrow, the migration file is written, and nobody has agreed on what happens if it goes wrong halfway through. That is the moment these seven Gemini prompts for database migrations are for. Each one covers a single decision: the order of steps, the backfill, the rollback, the verification query. Run them the night before, not during the incident.
Quick checklist
- — The migration is split into steps that can each be shipped alone.
- — Old and new code can read the schema at the same time.
- — A backfill script exists, and it is safe to run twice.
- — There is a rollback path that does not lose rows.
- — Large indexes are created without locking the table for the whole build.
- — Verification queries are written before the deploy, not after.
The prompts
1. Step plan from a schema change
I need to change my [database engine] schema like this: [describe the change]. Break it into migration steps that can ship independently, and say what code must deploy with each one.
What it does: Turns one risky migration into a sequence you can stop between.
How to use: Replace [database engine] and [describe the change]; keep each step reversible on its own.
2. Zero-downtime column rename
I need to rename column [old column] to [new column] in table [table name] with no downtime. Give me the expand and contract sequence, including the code changes at each stage.
What it does: Avoids the classic rename that breaks the app for the length of a deploy.
How to use: Replace [old column], [new column], and [table name]; do not drop the old column until the new one is fully read.
3. Idempotent backfill script
Write a backfill script for table [table name] that fills [new column] from [source column]. It must be safe to re-run, batch its updates, and log progress.
What it does: Gives you a script you can stop and restart without double-writing anything.
How to use: Replace [table name], [new column], and [source column]; test the batch size on a copy first.
4. Rollback plan
Write a rollback plan for this migration: [migration summary]. For each step, say how to undo it, how long the undo takes, and what data would be lost.
What it does: Makes the cost of retreat explicit before anyone needs it.
How to use: Replace [migration summary]; if a step cannot be undone, say so in the release notes.
5. Index build without a long lock
I need to add an index on [table name] ([columns]) in [database engine]. Give me the statement that builds it without blocking writes, and what to check while it runs.
What it does: Keeps a big table writable during the index build.
How to use: Replace the table, columns, and engine; confirm the syntax for your exact version.
6. Type change safety review
Review this type change for risk: [old type] to [new type] on column [column name] in table [table name]. List what can fail, what gets truncated, and how to test it on a copy.
What it does: Catches the silent truncation that only shows up in production data.
How to use: Replace the four values; run the test on a restore of real data, not an empty table.
7. Verification queries after deploy
Write verification queries for this migration: [migration summary]. Cover row counts, null checks on [new column], orphaned foreign keys, and a simple sample of migrated rows.
What it does: Gives you a yes-or-no answer instead of a feeling that it probably worked.
How to use: Replace [migration summary] and [new column]; run them immediately after the deploy and again an hour later.
How to score your own output
- You can explain the migration to a teammate in four sentences, in order.
- Every step has a rollback that someone other than you could run.
- The verification queries return the numbers you expected, not just “no errors”.
Keep going
- Browse the Coding prompt library
- Gemini prompts for ORM queries
- ChatGPT prompts for unit tests
- Gemini prompts for executive data presentations
These prompts are free to use. Copy them, tweak the [variables], ship something.