Migration Locking and Safety Review
Review a schema migration for locking, downtime, data-loss and rollback risks before it runs against a live database.
When to use it
Use it before applying a migration to a database that is serving traffic. It looks at each statement for locks that could block reads or writes, long table rewrites, destructive changes and mismatches between the migration and the application code that runs during the deployment.
When not to use it: It is not a substitute for rehearsing the migration on a production-sized copy of the data. Lock behaviour varies by database engine and version, so do not treat its statements about locking as facts without checking your engine's documentation.
Required inputs
| Placeholder | What to provide | Example |
|---|---|---|
| {{migration_sql}} | The full migration script, including any data backfill. | ALTER TABLE orders ADD COLUMN status_v2 text NOT NULL DEFAULT 'open'; CREATE INDEX idx_orders_status_v2 ON orders (status_v2); |
| {{database_engine}} | Database product and version, since locking differs between them. | PostgreSQL 15 |
| {{table_facts}} | Approximate row counts, write rate and how critical the tables are. Use 'unknown' where you do not know. | orders has about 40 million rows and receives continuous writes; read by the checkout service. |
| {{deployment_process}} | How the migration is deployed relative to the application, and whether old and new code run together. | Migration runs first, then a rolling deploy replaces application instances over about ten minutes. |
The prompt
Fill in each {{placeholder}} before you send it.
You are a database reliability engineer reviewing a migration before it is applied to a live system. Be specific and cautious.
<migration_sql>
{{migration_sql}}
</migration_sql>
<database_engine>
{{database_engine}}
</database_engine>
<table_facts>
{{table_facts}}
</table_facts>
<deployment_process>
{{deployment_process}}
</deployment_process>
For each statement in the migration, assess:
1. Locks: what lock it is likely to take on the engine and version given, whether that blocks reads or writes, and for roughly how long relative to the table size. If the behaviour depends on the engine version or settings, say so and name the documentation section to check rather than asserting it.
2. Rewrites and scans: whether it rewrites the table or scans it.
3. Data risk: anything destructive or irreversible, truncation, type narrowing, dropped constraints or columns, backfills that could fail halfway.
4. Compatibility: whether the old application code can still run against the new schema and whether the new code can run against the old schema, during the rolling deploy.
5. Rollback: how to undo it, and what cannot be undone.
Then propose a safer sequence if one is needed: smaller steps, concurrent or online alternatives that the engine supports, batched backfills, and which deployments must happen between steps.
Rules:
- Never claim that a statement is safe because it is common. Explain why, or say you are unsure.
- Do not invent engine features. If you are not certain that an option exists in the stated version, say so and tell me what to verify.
- Do not assume row counts or traffic beyond what is stated. Where size matters and is unknown, say that the risk cannot be judged.
- Do not rewrite the migration in full unless it needs restructuring; show the changed statements.
Output format:
Statement-by-statement table: statement | lock and impact | duration risk | data risk | compatible with old or new code | rollback
Overall risk (Low, Medium, High) with the main reason
Safer sequence (numbered, if needed)
Things to verify in the engine documentation
Rehearsal checklistExpected output
A statement-by-statement table covering locks, rewrite risk, data risk, deploy compatibility and rollback, followed by an overall risk level and a safer multi-step sequence where needed. For the example, a good response flags the index creation as potentially blocking writes unless built in a non-blocking way, questions the NOT NULL default on a very large table depending on the engine version, and asks which application version is running mid-deploy.
Overall risk: Medium, mainly the index build on a 40-million-row table receiving continuous writes.
Statement table (excerpt)
CREATE INDEX idx_orders_status_v2 ... | A plain index build may block writes to the table for its duration on this engine (verify in the documentation for your version) | High for a table this size | none | old code unaffected | DROP INDEX
Safer sequence
1. Add the column as nullable with no default in one migration.
2. Backfill in batches of limited size, outside peak traffic.
3. Build the index using the engine's non-blocking option, in its own step, because that option may not run inside a transaction.
4. Deploy the application that reads the new column.
5. Add the NOT NULL constraint after the backfill is complete and verified.
Things to verify
- How column defaults are handled on PostgreSQL 15 for the type used.Limitations
- Lock levels and rewrite behaviour differ by engine and version. The assistant can be out of date or wrong, so verify against official documentation.
- It has no knowledge of your real data volumes, indexes or long-running transactions, all of which change how risky a statement is.
- It cannot measure duration. Only a rehearsal on realistic data can.
- Orchestration tools wrap migrations in transactions differently, which affects which online options can be used.
How to validate the output
Do these before relying on anything the model returns.
- Written by
- PromptFable Editorial
- Last updated 13 Nov 2026
- Review
- Not yet reviewed
PromptFable is independent and is not affiliated with, endorsed by or sponsored by Anthropic, Google, OpenAI or any other vendor. Claude, Gemini, Google AI Studio and other product names are trademarks of their respective owners.