$npx -y skills add sabahattink/antigravity-fullstack-hq --skill prisma-workflowPrisma ORM best practices, schema design, migrations, seeding, and query optimization for PostgreSQL. Use when working with database schemas, migrations, or Prisma queries.
| 1 | # Prisma Workflow |
| 2 | |
| 3 | ## Schema Design |
| 4 | |
| 5 | ```prisma |
| 6 | model User { |
| 7 | id String @id @default(cuid()) |
| 8 | email String @unique |
| 9 | name String? |
| 10 | role Role @default(USER) |
| 11 | posts Post[] |
| 12 | createdAt DateTime @default(now()) |
| 13 | updatedAt DateTime @updatedAt |
| 14 | |
| 15 | @@index([email]) |
| 16 | } |
| 17 | |
| 18 | model Post { |
| 19 | id String @id @default(cuid()) |
| 20 | title String |
| 21 | content String? |
| 22 | published Boolean @default(false) |
| 23 | author User @relation(fields: [authorId], references: [id], onDelete: Cascade) |
| 24 | authorId String |
| 25 | |
| 26 | @@index([authorId]) |
| 27 | } |
| 28 | |
| 29 | enum Role { |
| 30 | USER |
| 31 | ADMIN |
| 32 | } |
| 33 | ``` |
| 34 | |
| 35 | ## Migration Workflow |
| 36 | |
| 37 | 1. Edit `schema.prisma` |
| 38 | 2. `npx prisma migrate dev --name descriptive_name` |
| 39 | 3. Review generated SQL in `prisma/migrations/` |
| 40 | 4. Test on development |
| 41 | 5. `npx prisma migrate deploy` for production |
| 42 | |
| 43 | ### Good Migration Names |
| 44 | |
| 45 | ```bash |
| 46 | npx prisma migrate dev --name add_user_role |
| 47 | npx prisma migrate dev --name create_posts_table |
| 48 | npx prisma migrate dev --name add_index_on_email |
| 49 | ``` |
| 50 | |
| 51 | ## Query Patterns |
| 52 | |
| 53 | ### Select Specific Fields |
| 54 | |
| 55 | ```typescript |
| 56 | const user = await prisma.user.findUnique({ |
| 57 | where: { id }, |
| 58 | select: { id: true, email: true, name: true } |
| 59 | }) |
| 60 | ``` |
| 61 | |
| 62 | ### Include Relations |
| 63 | |
| 64 | ```typescript |
| 65 | const user = await prisma.user.findUnique({ |
| 66 | where: { id }, |
| 67 | include: { posts: true } |
| 68 | }) |
| 69 | ``` |
| 70 | |
| 71 | ### Pagination |
| 72 | |
| 73 | ```typescript |
| 74 | const users = await prisma.user.findMany({ |
| 75 | skip: (page - 1) * limit, |
| 76 | take: limit, |
| 77 | orderBy: { createdAt: 'desc' } |
| 78 | }) |
| 79 | ``` |
| 80 | |
| 81 | ### Transactions |
| 82 | |
| 83 | ```typescript |
| 84 | await prisma.$transaction([ |
| 85 | prisma.user.update({ where: { id }, data: { balance: { decrement: 100 } } }), |
| 86 | prisma.order.create({ data: { userId: id, amount: 100 } }) |
| 87 | ]) |
| 88 | ``` |
| 89 | |
| 90 | ## Performance Tips |
| 91 | |
| 92 | - Always index foreign keys |
| 93 | - Use `select` to fetch only needed fields |
| 94 | - Use `take` for large tables |
| 95 | - Batch operations with `createMany` |
| 96 | - Use transactions for related operations |
| 97 | |
| 98 | ## Prisma Service (NestJS) |
| 99 | |
| 100 | ```typescript |
| 101 | @Injectable() |
| 102 | export class PrismaService extends PrismaClient implements OnModuleInit { |
| 103 | async onModuleInit() { |
| 104 | await this.$connect() |
| 105 | } |
| 106 | } |
| 107 | ``` |