Prisma Migration Helper
This skill streamlines the database migration workflow with proper naming conventions and validation.
Workflow
- •
Detect Schema Changes
- •Check if
apps/api/prisma/schema.prismahas uncommitted changes - •Verify changes are intentional
- •Check if
- •
Generate Migration Name
- •Follow convention:
add_table_name,update_field_type,remove_column_name - •Examples:
- •
add_order_notes- Adding new table - •
update_price_to_bigint- Changing field type - •
add_restaurant_timezone- Adding new field
- •
- •Ask user for descriptive name if changes are complex
- •Follow convention:
- •
Create Migration
bashcd apps/api && npx prisma migrate dev --name <migration-name>
- •
Regenerate Prisma Client
bashnpx prisma generate
- •
Verify Migration
- •Check migration file was created in
apps/api/prisma/migrations/ - •Show the generated SQL for review
- •Verify no syntax errors
- •Check migration file was created in
- •
Post-Migration Checks
- •Remind to test migration on fresh database before committing
- •Check if any packages depend on shared-types and suggest rebuilding:
bash
cd apps/storefront && npm run build cd apps/dashboard && npm run build
- •
Important Reminders
- •Never edit migration files manually after creation
- •Test migrations on fresh database:
docker compose down -v && docker compose up -d - •Always run
npx prisma generateafter schema changes - •Consider impact on existing data (add default values for NOT NULL columns)
Error Handling
If migration fails:
- •Check for breaking changes (removing required fields without defaults)
- •Verify database is accessible
- •Check for conflicting migrations
- •Suggest using
npx prisma migrate resetfor development (WARNING: deletes all data)
OpenOrder-Specific Patterns
- •Prices in cents: Always use
Intfor monetary values, neverFloat - •Timestamps: Use
@default(now())forcreatedAt,@updatedAtforupdatedAt - •Encrypted fields: Use
Jsontype forposConfig,paymentConfig - •Sequences: Use
@default(autoincrement())fororderNumberper restaurant