How to create unique constraint on a column for a foreign key?

So I am trying to create a colours table, and a user should be able to add new colours with a unique name, but only for the tenant they belong to.

For example, lets say a user adds "Blue" colour for tenant id 1, they can no now longer add "Blue" for tenant id 1, but they can for tenant id 2. How do I add this constraint at the schema level with drizzle.

The reason I need this is because my app is multi-tenanted and I need to seperate the data between tenants, as I am only using 1 database and dont want users from another tenant to see data that isnt theirs.

I have seen stuff about indexes and stuff on the drizzle docs, but I am not sure that is correct one to use or not.

Thanks for the help
image.png
Was this page helpful?