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.
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
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.
Related prompts
Get thorough code reviews with actionable feedback tailored to your language, framework, and standards.
Context-Aware Code CompletionProviding the surrounding code and project context lets the model match existing patterns exactly. The constraint against modifying existing code prevents unwanted side effects.
Inline Code SuggestionConstraining suggestions to match existing style and scope produces insertions that feel native to the codebase. The 'no explanation' rule mimics real inline completion behavior.
Code ExplanationThe audience level parameter adjusts complexity automatically. Requiring a usage example ensures the explanation is practical, not just theoretical.