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

Case insensitive unique constraint #3851

Open
mohaafaridd opened this issue Oct 4, 2020 · 5 comments
Open

Case insensitive unique constraint #3851

mohaafaridd opened this issue Oct 4, 2020 · 5 comments
Labels
domain/psl Issue in the "PSL" domain: Prisma Schema Language domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. kind/feature A request for a new feature. topic: indexes topic: schema

Comments

@mohaafaridd
Copy link

mohaafaridd commented Oct 4, 2020

Problem

It's really important to keep the casing in some of our columns which are unique ( cannot be duplicated ) which constraint can be overridden so easily by just change the casing

Suggested solutions

I've found some articles and the most matching one is this
Within schema it'd be great having

model Blog {
	...
	name String @unique(mode:"insensitive")
}

Alternatives

The second solution which is the only available at the moment is to create another column with lowercased letters and it'll be the unique one

@mohaafaridd mohaafaridd changed the title Case unsensitive unique constraint Case insensitive unique constraint Oct 4, 2020
@pantharshit00
Copy link
Contributor

This is more likely to be solved by citext support in schema. That will come eventually via #3447 although since citext is an extension instead of built in postgres type, it can take more time.

After that you could possibiliy do:

model Blog {
  ...
  name String @pg.Citext @unique
}

@probablycorey
Copy link

It doesn't look like #3447 supports a citext db type for postgres. Are there any plans to support the functionality that @Mohammed-Farid described?

@albertoperdomo albertoperdomo added the domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. label Feb 1, 2021
@albertoperdomo
Copy link
Contributor

@probablycorey Yes, we are adding support Citext as a type. This is scheduled for 2.16.0. I will also update #3447.

@albertoperdomo
Copy link
Contributor

@Mohammed-Farid Does using Citext work for you as a solution?

@mohaafaridd
Copy link
Author

@albertoperdomo Yes it should fix it as @pantharshit00 has shown previously

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain/psl Issue in the "PSL" domain: Prisma Schema Language domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. kind/feature A request for a new feature. topic: indexes topic: schema
Projects
None yet
Development

No branches or pull requests

5 participants