Database Migration Guide

Claude Codeclaude-codedatabasemigrationsschema

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

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

What you get when you save this prompt

Your workspace unlocks powerful tools to iterate and improve.

AI OPTIMIZE

AI Optimization

One-click improvement with structure analysis and pattern suggestions.

VERSION DIFF

Version History

Track every edit. Compare versions side-by-side with word-level diffs.

ORGANIZE
Development
Code Review
Testing
Marketing

Folders & Tags

Organize your library with nested folders, tags, and drag-and-drop.

MCP
$ npm i -g @promptingbox/mcp
Claude · Cursor · ChatGPT

Use Everywhere

Access prompts from Claude, Cursor, ChatGPT & more via MCP integration.

Your prompts, organized

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