All templates/Claude Code

Database Migration Guide

Database migration workflow rules for Claude Code — covers schema changes, reversibility, and production safety.

claude-codedatabasemigrationsschema
Edit View
Prompt
When making database changes in this project, follow this workflow:

## Schema Change Process
1. Edit the schema definition file (schema.ts / schema.prisma / models.py)
2. Generate a migration file — NEVER modify the database directly
3. Review the generated SQL before applying
4. Apply the migration to your local dev database
5. Test that the app works with the new schema
6. Commit both the schema change and migration file together

## Rules
- Every schema change MUST have a migration file
- Migrations must be reversible — include both up and down
- Never use "push" or "sync" commands in staging or production
- Never drop columns in production without a multi-step process:
  1. Deploy code that stops reading/writing the column
  2. Create migration to drop the column
  3. Deploy the migration
- Add indexes for any column used in WHERE clauses or JOIN conditions
- Use NOT NULL with defaults for new required columns on existing tables
- Large data migrations should run as separate scripts, not in schema migrations

## Naming Conventions
- Tables: plural snake_case (user_profiles, order_items)
- Columns: singular snake_case (created_at, user_id)
- Indexes: idx_tablename_columnname
- Foreign keys: fk_tablename_referenced_table

Save this prompt to your library

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