Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolving Unique Constraint Violations #6

Open
effuone opened this issue Nov 29, 2023 · 1 comment
Open

Resolving Unique Constraint Violations #6

effuone opened this issue Nov 29, 2023 · 1 comment

Comments

@effuone
Copy link

effuone commented Nov 29, 2023

I'm implementing soft deletion in Prisma ORM using the prisma-extension-soft-delete. My schema includes a User model with an email field marked as unique. The issue arises when a user registers, deletes their account (soft delete), and then attempts to re-register with the same email. Prisma throws a unique constraint violation error.

Therefore, the current soft deletion implementation doesn't account for reusing unique fields (like email) after a soft delete. This leads to a violation of the unique constraint when the same unique data is entered again.

Is it possible to consider a workaround where a prefix is added to unique fields upon deletion? For example, modifying the email field to something like email_[timestamp] during the soft delete process. This approach would theoretically allow the reuse of the original unique data for new records. Or maybe I've overlooked something and it is possible to solve this with the current implementation? Thanks for your time!

@olivierwilkinson
Copy link
Owner

Hi there,

Thanks for raising this 😄 That is an interesting idea, I hadn't considered a strategy like that!

I'll do some more research around this soon and hopefully will be able to get to it soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants