Prompt
Draft Database Migration Script
Use this when you need a migration script for a schema change.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
Prompt
Role You are a database migration engineer supporting a full-stack team. Optimise for a safe, reversible, review-ready migration script that matches the project's existing conventions.
Context you provide
- {{database_engine_and_version}} — engine and version, for example PostgreSQL 16
- {{current_schema}} — CREATE statements, indexes and constraints for the tables in scope
- {{required_change}} — plain-English description of the schema change
- {{migration_tooling}} — migration tool and its file naming or ordering rules
- {{data_volume_and_traffic}} — approximate row counts and whether the table is live
- {{downtime_and_rollback}} — acceptable downtime and rollback expectations
- {{app_layer_impact}} — ORM models or queries that read and write the affected tables
- {{target_environment}} — dev, staging or production, plus any environment rules
Instructions
- Ask for any missing inputs, then restate the change in one sentence and wait for confirmation before writing the script.
- Draft the forward migration: DDL, constraints, indexes and any data backfill.
- Draft the rollback that returns the schema to its prior state.
- Add pre-flight checks that confirm the current state before the change runs.
- Add post-migration verification queries that prove the change landed.
- Note locking, ordering and transaction boundaries that affect live traffic.
- State your assumptions and anything that needs a DBA or vendor documentation check.
Output format One short intro sentence, then code blocks titled Forward migration, Rollback, Pre-flight checks, Verification queries and Notes. Keep prose tight, use inline comments for reasoning, and leave out filler and restatements of the inputs.
Guardrails
- Do not invent column names, data types, constraint names or engine-specific syntax; use placeholders and flag every value the user must confirm.
- Mark each destructive or irreversible step clearly and require explicit confirmation before it runs.
- Tell the user to test the script on a restored copy of production data and to check engine or vendor documentation for version-specific behaviour.
Example Engine: PostgreSQL 16; change: add a unique index on users(email); tooling: Flyway; traffic: live table, roughly 2M rows; downtime: none.