Back to guide/Developer Tools

Database Migration Writer

Claude Code can read the current schema file, understand the ORM conventions, and generate both the migration code and SQL. Cursor handles this well with file references. The safety checklist prevents common migration pitfalls.

cursor-vs-claude-codemigration_descriptionorm_nameschema_file_path
Edit View
Prompt
Write a database migration for the following change:

Change: {{migration_description}}
ORM: {{orm_name}}
Current schema: (read from {{schema_file_path}})
Database: {{database_type}}

Requirements:
1. Generate both the schema change (ORM model) and the raw SQL migration file
2. Handle the migration safely:
   - Add columns as nullable first if they'll be NOT NULL (backfill, then alter)
   - Use IF NOT EXISTS / IF EXISTS guards where supported
   - For column renames, use a two-step approach in prod (add new, migrate data, drop old)
3. Include a rollback/down migration
4. If adding indexes, consider:
   - CREATE INDEX CONCURRENTLY for large tables (PostgreSQL)
   - Composite index column ordering (most selective first)
5. If the table has RLS enabled, update policies if the new columns need them

After writing the migration:
- Estimate the impact on a table with {{row_count}} rows
- Flag any operations that will lock the table
- Note if this migration is backward-compatible with the current application code

Variables to customize

{{migration_description}}{{orm_name}}{{schema_file_path}}{{database_type}}{{row_count}}

Why this prompt works

Claude Code can read the current schema file, understand the ORM conventions, and generate both the migration code and SQL. Cursor handles this well with file references. The safety checklist prevents common migration pitfalls.

Save this prompt to your library

Organize, version, and access your best prompts across ChatGPT, Claude, and Cursor.