Database Migration Guide
Use this skill when the User Request requires changes to the database schema (prisma/schema.prisma).
Pre-requisites
- •Ensure Docker is running and the database container is healthy.
- •Be cautious with destructive changes (e.g., removing columns).
Workflow
- •
Edit Schema: Modify
backend/prisma/schema.prisma.- •Add new models, fields, or enums.
- •Ensure relations are correctly defined on both sides.
- •
Migration: Create a new migration file.
powershell# Run from backend directory # Name the migration meaningfully (e.g., add_user_subscription) npx prisma migrate dev --name [migration_name]
- •
Generate Client: Update the Prisma Client.
powershellnpx prisma generate
- •
Verification:
- •Check the generated migration SQL in
backend/prisma/migrations/. - •(Optional) If data migration is needed, write a script.
- •Check the generated migration SQL in
- •
Integration:
- •Update DTOs and TypeDefinitions to reflect schema changes.
- •Update any code relying on the changed models.
Safety Rules
- •NEVER modify an existing migration file after it has been applied. Create a new migration instead.
- •NEVER use
prisma db pushin production-like environments; usemigrate deploy. - •ALWAYS verify that
npx prisma generatewas run after migration to update the client types.