Prompt file imported from JishnuVenugopal1994/Supervisor_Monitoring_App (
.github/prompts/create-prisma-migration.prompt.md). Fill in{{input}}before use. Copyright stays with the author.
Add the following to the Prisma schema: {{input}}
Follow these steps in order:
-
Read
backend/prisma/schema.prismato understand the current schema before making any changes. -
Edit
schema.prisma- Apply naming conventions: PascalCase models, camelCase fields, SCREAMING_SNAKE_CASE enum values
- For new models: add
id String @id @default(cuid()),createdAt DateTime @default(now()),updatedAt DateTime @updatedAt - For new non-nullable columns on existing models: always add
@default(...)or make the field optional (?) to avoid breaking the existing migration history - Define both sides of any new relation
- Use
onDelete: Cascadefor child records;onDelete: Restrictfor referenced master records
-
Generate and name the migration
- Run:
cd backend && npx prisma migrate dev --name <descriptive_name> - Use snake_case for migration names (e.g.,
add_shift_template_model,add_priority_to_work_order) - Do NOT edit the generated migration SQL file
- Run:
-
Update
backend/prisma/seed.ts- Add seed entries for any new required model using
upsert(notcreate) so it's idempotent - If a new required field was added to an existing model, update existing seed entries to include it
- Add seed entries for any new required model using
-
Check application code
- Search for any TypeScript types, interfaces, or Zod schemas that manually mirror the changed model — update them to match
- If a new model was added, note which service file (
src/services/) should be created to handle its CRUD operations
-
Validate
- Run
cd backend && npx prisma generateto confirm TypeScript types are updated - Run
cd backend && npx prisma db seedto confirm seed still runs cleanly
- Run
Reference backend/prisma/schema.prisma and backend/prisma/seed.ts for current patterns.