soft delete with unique constraint
Hello guys ! How to make username unique only for non-deleted users in Prisma?
I'm using Prisma with postgres and I have a User model with a deletedAt field for soft deletes. I want to make sure that username is unique only when deletedAt is null (i.e., for active users). It's okay if deleted users have the same username.
I tried this:
@@unique([username, deletedAt])
But it still allows multiple users with the same username and deletedAt = null.
i will attach my schema in image
I'm using Prisma with postgres and I have a User model with a deletedAt field for soft deletes. I want to make sure that username is unique only when deletedAt is null (i.e., for active users). It's okay if deleted users have the same username.
I tried this:
@@unique([username, deletedAt])
But it still allows multiple users with the same username and deletedAt = null.
i will attach my schema in image
