Prisma can't filter the value null on prisma.findUnique if my unique index is a DateTime

Viewed 2183

My schema.prisma model is the next one:

model User {
    id        String    @id @db.VarChar(255)
    email     String    @db.VarChar(255)
    createdAt DateTime  @default(now()) @map("created_at") @db.Timestamptz(6)
    updatedAt DateTime  @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(6)
    deletedAt DateTime? @map("deleted_at") @db.Timestamptz(6)

    @@unique([email, deletedAt])
    @@map("user")
}

My unique key on the column email is associate with the other column deletedAt because I want to be able to use the email again after a user is deleted.

The query to get a user by his email should be simple. Where the email equal and where deletedAt is null. I tried the next js command with prisma.

const account = await this.prisma.user.findUnique({ where: { email_deletedAt: { email: 'user@exemple.com', deletedAt: null } } });

I got this error:

Argument deletedAt: Got invalid value null on prisma.findUniqueUser. Provided null, expected DateTime.

In my model, I explicitly say that deletedAt could be null, but this query doesn't seem to expect a nullable value... Am I doing something wrong?

0 Answers
Related