Plan a zero-downtime database migration
Creates a step-by-step expand-and-contract plan for a schema or data change, with backfill, verification, and rollback at each step.
The prompt
Help me plan a database migration that won't cause downtime or data loss.
Database and version: [e.g. "PostgreSQL 15", "MySQL 8", "MongoDB"]
Current schema: [RELEVANT TABLES/COLLECTIONS]
Change I need: [e.g. "rename a column", "split a table", "change a column type", "add NOT NULL"]
Table size and traffic: [ROW COUNT, WRITES PER SECOND - or "unknown"]
How the app is deployed: [e.g. "rolling deploys, old and new versions run together for 10 minutes"]
Migration tooling: [e.g. "Rails migrations", "Flyway", "Alembic", "raw SQL"]
Produce a phased plan using expand-and-contract:
1. Expand: additive schema changes that old code tolerates.
2. Dual-write or sync: how new data reaches both shapes.
3. Backfill: batched approach, batch size guidance, throttling, and how to resume if it stops.
4. Verify: queries to compare old and new data before switching reads.
5. Switch reads, then stop old writes.
6. Contract: remove old columns or tables only after a safe waiting period.
For every phase include: the deploy or migration step, the SQL or pseudo-code, what could go wrong, how to detect it, and how to roll back.
Specifically flag operations that may take long locks or rewrite the table on my database (e.g. adding a column with a default, creating indexes without the concurrent option, changing types) and the safer alternative. If behavior depends on the exact version, say "[CONFIRM for my version]" instead of guessing.
End with a pre-flight checklist: backups verified, tested on a production-sized copy, monitoring in place, owner on call.
Highlighted [brackets] are blanks to replace with your own details.
Fill in the blanks and use this promptMore Software Development prompts
What to fill in
- e.g. "PostgreSQL 15", "MySQL 8", "MongoDB"
- RELEVANT TABLES/COLLECTIONS
- ROW COUNT, WRITES PER SECOND - or "unknown"
- e.g. "Rails migrations", "Flyway", "Alembic", "raw SQL"
- CONFIRM for my version
How this prompt is built
This prompt follows the Few-Shot structure (Few-shot prompting). A few-shot prompt includes one or more worked examples of the input and the output you want, so the model can copy the pattern instead of guessing it.
Related prompts
- Design a caching strategy with safe invalidationDecides what to cache, where, and for how long, with invalidation rules and failure modes so the cache doesn't serve wrong data.
- Refactor code to be cleaner and easier to maintainImproves structure, naming, and design without changing behavior.
- Design a database schemaEntities, relationships, keys, indexes, and migrations for your data model.
- Analyze logs to find what went wrongReads logs to identify errors, patterns, and the likely root cause.