prisma / prisma-client-js

Type-safe database client for TypeScript & Node.js (ORM replacement)
Apache License 2.0
1.47k stars 67 forks source link

@@unique constraint doesn't handle non-scalar types #582

Closed weaversam8 closed 4 years ago

weaversam8 commented 4 years ago

I believe this is strongly related to prisma/prisma2#1681, and could be a regression on prisma/prisma2#1377.


In one of my models, I have a model that looks similar to this snippet:

model User { ... }
model Item { ... }

model Sprint {
  id String @id @default(cuid())

  user      User
  items     Item[]
  startDate DateTime
  endDate   DateTime

  createdAt DateTime @default(now())

  @@unique([user, startDate, endDate])
}

But I think the @@unique attribute only handles the startDate and endDate components. My parser isn't panicking, but it is creating a type called StartDateEndDateCompoundUniqueInput which ignores user entirely when doing sprint.upsert(...)

type StartDateEndDateCompoundUniqueInput {
  startDate: DateTime
  endDate: DateTime
}

Is the @@unique constraint completely ignoring non-scalar types in this example?

pantharshit00 commented 4 years ago

@weaversam8 I was unable to reproduce this with preview024: image

User is avaliable for use. Can you please make sure you are on the latest version and please try this again?

weaversam8 commented 4 years ago

You're correct. This issue occurred in preview023 but not preview024. This can be considered resolved.


For anyone who needs to upgrade the version, this is the command I used:

yarn upgrade prisma2@2.0.0-preview024 @prisma/client@2.0.0-preview024

I'm pretty sure just including prisma2@2.0.0-preview024 would be fine.