0

Using Prisma's unique indexes: https://www.prisma.io/docs/concepts/components/prisma-schema/data-model#defining-a-unique-field

Is it possible to do something like the following (pseudo):

model Foo {
  id               String           @id @default(uuid())
  name             String
  userId           String
  createdAt        DateTime         @default(now())
  updatedAt        DateTime         @updatedAt
  type             FooType
  @@unique([userId, FooType.bar])
}

enum FooType {
  bar
  baz
}

The resulting constraint would state, "there cannot be more than 1 row with a userId of X and a FooType of bar (more than 1 baz is fine)"

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.