Overview
KAIU Natural Living uses Prisma for database migrations and schema management. This guide covers creating, applying, and managing migrations.Migration Strategy
The project currently usesprisma db push for development, which:
- Syncs schema changes directly to the database
- Does not create migration files
- Best for rapid prototyping
Development Workflow
Making Schema Changes
model Product {
id String @id @default(uuid())
sku String @unique
name String
// Add new field:
featured Boolean @default(false)
// ...
}
Production Workflow (Prisma Migrate)
For production environments, use formal migrations:Creating Migrations
prisma/migrations/Applying Migrations
Production Deployment
- Applies pending migrations
- Does not prompt for confirmation
- Safe for automation
Development Sync
If another developer created migrations:Common Migration Tasks
Add a New Model
Add a Relation
Rename a Field
Add an Index
Make a Field Optional/Required
PostgreSQL Specific Features
Enable Extensions
For pgvector (AI embeddings):Using Unsupported Types
For PostgreSQL-specific types not directly supported by Prisma:Seeding After Migrations
After schema changes, reseed the database:Rollback Strategies
Development Rollback
Reset the entire database:Production Rollback
Create a new migration that reverses changes:Migration Best Practices
- Test Locally First - Always test migrations on development database
- Backup Production - Create database backup before applying migrations
- Small Changes - Keep migrations focused and atomic
- Descriptive Names - Use clear migration names:
add_user_roles,create_reviews_table - Review Generated SQL - Check migration files for correctness
- Version Control - Commit migration files with related code changes
Troubleshooting
Migration Out of Sync
If migrations are out of sync:Schema Drift
If database schema differs from Prisma schema:Failed Migration
Environment-Specific Migrations
Development
Staging/Production
Next Steps
- Review Prisma Schema Documentation
- Learn about Database Seeding
- Explore API Reference