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)"