This guide covers how to manage database migrations in Echo using Prisma.
When you make changes to the schema in prisma/schema.prisma, create a new migration:
bunx prisma migrate dev --name <descriptive_name>Example migration names:
- add_user_email
- update_ticket_status_enum
- create_achievements_table
This will:
- Save your schema changes to a new migration file
- Execute all pending migrations
- Regenerate the Prisma Client
In development:
bunx prisma migrate devIn production:
bunx prisma migrate deployThe key difference is that migrate dev is for development environments where you can afford data loss, while migrate deploy is for production where data preservation is critical.
Major schema updates will be documented here.
-
User Model
- Added email field (optional)
- New roles and permissions
- Added relationships to new models
-
Message Model
- Added internal flag for staff-only messages
- New relationship to tickets
-
Ticket Model
- Added escalation support
- Enhanced agent assignment system
-
Migration Conflicts If you get migration conflicts: ```bash bunx prisma migrate reset --force
⚠️ Warning: This will delete all data. Use only in development. -
Schema Drift If your database is out of sync:
bunx prisma migrate diff bunx prisma migrate reset
-
Failed Migrations - Always backup your database before migrations
- Check migration status:
bunx prisma migrate status - Review migration history in
prisma/migrations
- Check migration status:
To downgrade to a previous version:
- Revert migrations
- Install older package version
- Restore old configuration
If migrations fail:
- Backup database
- Reset migrations:
bunx prisma migrate reset
- Reapply migrations