Prisma Guide (Development & Production)
Development Workflow
Daily Operations
# Get latest changesgit pull
# Sync with databasenpx prisma db pull
# Generate clientnpx prisma generateSchema Changes
# After modifying schema.prismanpx prisma migrate dev --name description_of_changes
# Check through GUInpx prisma studioDatabase Reset (Dev Only)
# Removes all data and reapplies migrationsnpx prisma migrate resetSeed Data
# Populate database with test datanpx prisma db seedProduction Operations
Applying Migrations
# PRODUCTION ONLY - applies existing migrationsnpx prisma migrate deployStatus Check
# Check migration statusnpx prisma migrate statusSchema Management
Schema Validation
# Format schema.prismanpx prisma format
# Validate schemanpx prisma validateDatabase Synchronization
# Get current schema from databasenpx prisma db pull
# Push schema to database (dev only!)npx prisma db pushTeam Collaboration
Handling New Changes
git pullnpx prisma generateCreating Changes
# 1. Create branchgit checkout -b feature/name
# 2. Modify schema.prisma
# 3. Create migrationnpx prisma migrate dev --name description
# 4. Commit ALL filesgit add prisma/schema.prismagit add prisma/migrations/*git commit -m "feat: description"Important Rules
Production Restrictions
❌ Never use in production:
prisma migrate devprisma migrate resetprisma db push
Development Restrictions
❌ Never in development:
- Manually delete migration files
- Modify existing migrations
- Make direct database changes
Troubleshooting
Migration Conflicts
# 1. Save changesgit stash
# 2. Get latest changesgit pull
# 3. Reset databasenpx prisma migrate reset
# 4. Restore changesgit stash pop
# 5. Create new migrationnpx prisma migrate devSchema Drift
# Check current schemanpx prisma db pull
# Fix differencesnpx prisma migrate devProject Structure
prisma/ ├── schema.prisma # Main schema ├── migrations/ # Migration files └── seed.ts # Test data scriptEnvironment Variables
Development (.env)
DATABASE_URL="postgresql://user:password@localhost:5432/dbname"Production (.env.production)
DATABASE_URL="postgresql://prod_user:prod_pass@prod.host:5432/prod_db"Best Practices
✅ Always:
- Test migrations in dev before production
- Commit all migration files
- Use clear migration names
- Backup before applying production migrations
- Coordinate major schema changes with the team