loona
loona

Reputation: 1

Cleaner Way to Write Prisma Schema for Badge System

I'm working on a badge system for my web app and would appreciate any suggestions for cleaning up this Prisma schema

datasource db {
  provider = "mongodb"
  url      = env("DATABASE_URL")
}

model User {
//alot of code nobody should see
  badges         UserBadge[]
}

model Badge {
  id          String   @id @default(auto()) @map("_id") @db.ObjectId
  name        String
  icon        String
  users       UserBadge[]
}

model UserBadge {
  id       String @id @default(auto()) @map("_id") @db.ObjectId
  userId   String
  badgeId  String
  user     User   @relation(fields: [userId], references: [id])
  badge    Badge  @relation(fields: [badgeId], references: [id])

  @@unique([userId, badgeId])
}

Probably removing the UserBadge model.

Upvotes: 0

Views: 13

Answers (0)

Related Questions