I have this model in Prisma:
model RegisteredPage {
  id        Int      @id @default(autoincrement())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  domain String // instagram, youtube,...
  page   String // s4eed, dive, makeappwithme,...
}
I want to add a constraint on the domain and page so that combination of them is unique. Should I make the combination of them as ID?
You need to use the @@unique attribute.
Unique attributes can be defined on multiple fields using the @@unique  attribute, (also called composite or compound unique constraints).
This would define a composite unique index on combination of domain and page fields.
model RegisteredPage {
  id        Int      @id @default(autoincrement())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  domain String // instagram, youtube,...
  page   String // s4eed, dive, makeappwithme,...
  @@unique([domain, page])
}
Here's a Reference for using the @@unique attribute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With