Generate Database Migration and Rollback Specs for Coding Agents

Get a structured migration and rollback plan that ensures data integrity and zero-downtime execution for your database schema changes.

Agent prompt for Claude Code and Cursor

Prompt

Prompt
Act as a Senior Database Reliability Engineer. I will provide a schema change request. Your job is to generate a migration brief that ensures safety and atomicity. Follow these rules: 1. Always provide an explicit rollback script that reverses the change without data loss. 2. Include a LOCK_TIMEOUT setting for every DDL operation to prevent blocking production queues. 3. For adding columns, ensure the use of NULL or DEFAULT values that avoid full table locks on large datasets. 4. Define a specific verification test case for both the forward and rollback operations. Output format: ### Migration Details: [Title and target table] ### SQL Migration: [Code block] ### Rollback Script: [Code block] ### Safety Checklist: [List of locks and timeout settings] ### Verification Protocol: [Step-by-step validation steps]. This is technical guidance; verify all migrations in a staging environment before production. Ask me for the schema change details and current table size now.

Example output

Verification protocol for the user_status migrationTested on staging before the 50-million-row users table is touched
  1. Run migration on stagingStep 1Apply the ALTER TABLE with a 5s lock timeout
  2. Verify column existsStep 2Query information_schema.columns for user_status
  3. Insert dummy recordStep 3Check the default value is applied
  4. Run rollback scriptStep 4Drop the user_status column
  5. Verify column is absentStep 5Repeat the information_schema query

Example for: adding a user_status column to a 50-million-row users table. ### Migration Details: Add user_status to users table. ### SQL Migration: SET lock_timeout = '5s'; ALTER TABLE users ADD COLUMN user_status VARCHAR(20) DEFAULT 'active'; ### Rollback Script: SET lock_timeout = '5s'; ALTER TABLE users DROP COLUMN user_status; ### Safety Checklist: - Lock timeout set to 5 seconds to prevent transaction queueing. - Added column with DEFAULT value to avoid full table rewrite in Postgres 11+. - Migration is wrapped in an implicit transaction. ### Verification Protocol: 1. Run migration on staging instance. 2. Verify column exists: SELECT column_name FROM information_schema.columns WHERE table_name = 'users' AND column_name = 'user_status'; 3. Insert dummy record and check default value. 4. Run rollback script. 5. Verify column is absent: SELECT column_name FROM information_schema.columns WHERE table_name = 'users' AND column_name = 'user_status'.

Written by AI from this prompt. Your results will vary.

Tips and common edits

Why this works

  • Forces explicit inclusion of rollback scripts to ensure reversibility.
  • Mandates lock timeouts to prevent production database outages.
  • Requires specific validation steps to confirm migration success.

Use this prompt when you need to update production databases safely. Paste this into ChatGPT, Claude, or Cursor, then follow the agent's prompts to provide your SQL requirements and table context.

Common edits

  • Adjust the lock_timeout duration based on your specific database driver.
  • Add specific constraints like CHECK or UNIQUE if your migration requires them.

Reuse it: Use in a workflowAdapt in the builder

Prompt details

By
Prompts-GPT editors
Published
How prompts are written and checked

Did this prompt work?

AI Coding AgentsClaude Code

Create Automated Verification Loops for Long-Running Coding Agents

Generate a deterministic shell pipeline that combines linting, isolated unit testing, and diff-budget monitoring to validate AI agent code changes.

AI Coding AgentsClaude Code

Design a Sandbox Security Policy for Autonomous Coding Agents

Generate a rigorous security policy for autonomous agents to define allowed shell commands, file access boundaries, and network restrictions.

AI Coding AgentsClaude Code

Audit PR Git Diffs for Scope Creep and Churn

Reviews git diff statistics and patch files to immediately flag out-of-scope edits, accidental whitespace formatting churn, and unrequested dependency updates.

AI Coding AgentsClaude Code

Convert User Stories into Strict Acceptance Test Assertions

This prompt transforms vague business requirements into precise Given-When-Then test assertions with exact HTTP status codes and JSON payload structures for AI coding agents.

AI Coding AgentsClaude Code

Generate Reproducible Bug Fix Specs for Coding Agents

Get a standalone reproduction test script and a precise technical plan to fix a bug, ensuring your AI agent stays focused and avoids unnecessary file changes.

AI Coding AgentsClaude Code

Create a Legacy Module Reference Sheet for Coding Agents

Compresses messy legacy source files into a dense markdown cheat sheet capturing public methods, hidden state changes, and side effects for coding agent contexts.