Change the data type of some varchar
and text
columns to be citext
#23
Labels
database
Database schema related issues
varchar
and text
columns to be citext
#23
Why?
citext
is a Postgres extension that stores strings in a similar fashion totext
but when comparing values, it's case insensitive. This could be useful on some fields for either searching capabilities or to avoid strings that only have one letter changed.For searching capabilities, this would make it so for example, searching for
mario564
will make it so the userMario564
pops up, instead of having to search forMario564
. This is already possible using Postgres' ilike operator but I think it would simplify things a little bit more.The more important case is the second one. Putting another example, right now, there's a unique constraint on the
name
field on thetournament
table, which means there can't be two tournaments namedosu! World Cup 2023
, but if someone were to create one namedosu! world cup 2023
then it would be allowed since the casing for W and C are different, but using thecitext
data type makes it so the latter string violates the unique constraint ascitext
checks a string's uniqueness case insensitively.How?
We'd need to create a custom migration to add the extension to the database and then create a custom data type with Drizzle to maintain typesafety.
The affected tables and columns would be:
Citext Postgres docs: https://www.postgresql.org/docs/current/citext.html
Drizzle custom types docs: https://orm.drizzle.team/docs/custom-types
The text was updated successfully, but these errors were encountered: