thinkhard.SI

Prompt repository Engineering & code

Plan a database schema change without downtime

You need to rename, split or change a column or table on a live database and want a step-by-step plan that keeps the app working throughout.

Registry no.
ENG-016
Collection
Engineering & code
Laid out for
Claude
Score
10 out of 10
Blanks to fill
8
Added

Engineering & codeClaude

The prompt

Score 10 of 10, Excellent

Use it when You need to rename, split or change a column or table on a live database and want a step-by-step plan that keeps the app working throughout.

  • {{current_schema}}
  • {{change}}
  • {{database}}
  • {{table_sizes}}
  • {{deploy_process}}
  • {{migration_tool}}
  • {{code_paths}}
  • {{reviewers}}
Full prompt and why it works
System prompt
You are a senior backend engineer who plans database changes for production systems that cannot go down. You favor small, reversible steps, and you are explicit about what could lock a table or lose data.
User message
<current_schema>
{{current_schema}}
</current_schema>

<change>
{{change}}
</change>

<environment>
Database and version: {{database}}
Table sizes and traffic, as far as known: {{table_sizes}}
How the app is deployed (rolling deploys, how many app versions run at once): {{deploy_process}}
Migration tool: {{migration_tool}}
Code that reads or writes these tables: {{code_paths}}
</environment>

Write a step-by-step plan for making the change above without downtime, for {{reviewers}} to review before anyone runs it. Use the expand and contract approach where it applies: add the new structure, write to both, backfill, switch reads, then remove the old structure once nothing uses it.

For each step give what changes (schema, app code or data), the migration or code change in outline, whether old and new app versions both keep working during it, how to check it worked, and how to roll it back. Present the steps as a numbered list, then a summary table with the columns Step, Deploy or migration, Reversible (yes or no), Risk.

Then cover:
- Locking: which statements could lock or rewrite a large table on this database, and the safer form to use where one exists.
- Backfill: batch size, throttling, and how to resume if it stops halfway.
- Data checks: queries or counts that prove old and new data match before reads switch.
- The point of no return: the first step that cannot be undone without losing data.

A good plan is one where every step can ship on its own, be checked, and be undone until the point of no return. Keep it under 900 words. Mark any claim about how {{database}} behaves, for example whether adding a column with a default rewrites the table, as "verify for your version", because this differs between databases and versions. Do not invent table sizes or timings; if the plan depends on them, say what to measure first.

If the backfill needs a business rule I have not given, such as how to split existing values or what to use for rows with missing data, list it as an open question at the top rather than choosing one. If the change cannot be made safely without a maintenance window, say so plainly and explain why rather than forcing a plan.

Variables

{{current_schema}}
The table definitions involved, with indexes and constraints.
{{change}}
What you need to change and why, for example "split the name column into first_name and last_name for the new billing export".
{{database}}
The database and version, for example PostgreSQL 16 or MySQL 8.4.
{{table_sizes}}
Row counts and write traffic for the tables involved, or "unknown".
{{deploy_process}}
How code ships, for example "rolling deploys, old and new versions run together for about 10 minutes".
{{migration_tool}}
For example Rails migrations, Alembic, Flyway or plain SQL scripts.
{{code_paths}}
Services, files or queries that read or write these tables, as far as you know.
{{reviewers}}
Who reviews the plan, for example "the backend team and our database administrator".

Why it works

  • What good looks like. Every step must keep the old and new app versions working and come with its own check and rollback, which is what zero downtime means in practice.
  • If unsure. Database-specific behavior is marked "verify for your version", because locking rules differ between engines and releases and a confident wrong answer locks production.
  • What to avoid. No invented table sizes or timings; where the plan depends on them, it says what to measure first.

How to use it

  1. Press Fill in variables and type your details into each blank. What you type stays in this browser.
  2. Copy the filled prompt into the AI tool you already use, such as ChatGPT, Claude or Gemini, or open it in the Grader or the Prompt Tester here.
  3. Before you rely on it, try it on three or four real examples. The Prompt Tester runs them all at once and shows which ones go wrong.
Use it from code

Get this prompt as JSON from the free REST API, with your own text in the blanks, or let an AI assistant fetch it through the MCP server. No key.

curl -s https://thinkhard.si/api/v1/prompts/zero-downtime-schema-change

With the MCP server added to Claude, ChatGPT, Cursor or VS Code, call get_prompt with {"prompt": "zero-downtime-schema-change"}, or just ask for it by name.