[BUG] Prisma not supporting optional @unique indexes in MongoDB #23870
Labels
bug/1-unconfirmed
Bug should have enough information for reproduction, but confirmation has not happened yet.
kind/bug
A reported bug.
team/schema
Issue for team Schema.
topic: indexes
topic: mongodb
topic: prisma db push
CLI: prisma db push
topic: (@)@unique
Bug description
** THE PROBLEM**
OPTIONAL @unique indexes are erroring with duplicate
null/undefined
values.This means that two records that omit an optionally @unique field will clash
THE SOLUTION
What Prisma should be doing is setting Sparse = true on any index of an optional @unique field
But I am having to manually remember to do this for every index from an optional @unique
If we mark an OPTIONAL field
foo
@unique, run:db.collection.createIndex( { foo: 1 }, { unique:true, sparse: true } )
If we mark a REQUIRED field
foo
@unique, run:db.collection.createIndex( { foo: 1 }, { unique:true )
^ This is all prisma would have to do, currently it runs the second in both cases
This is how I'm manually editing the indexes created by Prisma:
How to reproduce
Expected behavior
No response
Prisma information
Environment & setup
Prisma Version
The text was updated successfully, but these errors were encountered: