Skip to Content
0
Jul 27, 2023 at 11:07 PM

Is it possible to have a conditional unique constraint annotation ?

62 Views

Let's assume I have the following entity...

entity MyEntity : cuid {
   userId       : String;
   active       : Boolean;
   field1       : String;
   field2       : String;
}

I want to add a unique constraint annotation for userId and active === true.

So I can have any number of entries with the same userId and active === false. But only one active userId.

Is it possible to do so ??