How to Handle Partial Unique Indexes with Prisma Migrations?
Hey Community,
I'm working on a use case where I need to manually modify a Prisma migration file to add a
WHERE clause to a unique index. For example:
The issue is that Prisma doesn't recognize this line afterwards. When I run prisma migrate dev, it tries to add the unique constraint again:
Is there any known workaround to prevent Prisma from re-adding this constraint?
Thanks in advance!3 Replies
You decided to hold for human wisdom. We'll chime in soon! Meanwhile,
#ask-ai is there if you need a quick second opinion.Hey!
It seems that you are running into this issue:
https://github.com/prisma/prisma/issues/13417
GitHub
Partial unique indexes are being recreated on every migration with ...
Bug description We are using partial unique indexes, since we are implementing soft delete-adding deletedAt column to our models. Since we want the columns to still behave as unique, we mark them w...
As a workaround, you can create an empty migration file and add the SQL to create a partial unique index in this migration
https://github.com/prisma/prisma/issues/6974#issuecomment-2489730870
GitHub
Conditional uniqueness constraints; Partial/Filtered (Unique) Index...
Problem I would like to be able to define a uniqueness constraint that has conditional elements to it so that it can map to and align with a conditional unique index/constraint within the database....