Database Migration Script Writer
Generate safe, reversible database migration scripts
Write a database migration for this change: **Current schema:** ```sql [PASTE_CURRENT_TABLE_DEFINITIONS] ``` **Desired change:** [DESCRIBE — e.g., "add a 'status' column to orders, add an index on user_id + created_at, rename 'name' to 'full_name'"] Generate: 1. **Up migration** — SQL to apply the change 2. **Down migration** — SQL to reverse it completely 3. **Data migration** (if needed) — backfill existing rows 4. **Zero-downtime check** — will this lock the table? If so, how to avoid it Safety checklist: - [ ] Uses IF NOT EXISTS / IF EXISTS to be idempotent - [ ] Handles NULL for new columns on existing rows - [ ] Doesn't break existing queries (backward compatible) - [ ] Includes a default value for new NOT NULL columns - [ ] Estimates lock time for large tables If the table has more than 1M rows, provide the migration in batches to avoid long locks. Also generate a test query to verify the migration worked correctly.
How to Use This Prompt
- 1Copy the prompt template above
- 2Paste into Claude, ChatGPT, or Cursor
- 3Replace [bracketed placeholders] with your specific project details
- 4Iterate on the AI output to refine and customize the results
More Database Prompts
Related database templates from the vault
Database Normalization Advisor
Use this prompt to database normalization advisor with AI assistance
Query Result Caching Strategy
Use this prompt to query result caching strategy with AI assistance
Database Schema Designer
Design a normalized database schema from application requirements
Database Sharding Strategy Designer
PRODesign a database sharding strategy with shard key selection, routing logic, and migration plan from a single database
You Might Also Like
Prompts from other categories that share similar tags
Database Deadlock Resolver
Use this prompt to database deadlock resolver with AI assistance
Database Backup and Restore Automation
Use this prompt to database backup and restore automation with AI assistance
Database Query Performance Analyzer
Analyze slow database queries and generate optimized alternatives
Data Dictionary Generator
Use this prompt to data dictionary generator with AI assistance
Keep Exploring the Vault