DEV Community

juffel
juffel

Posted on

Ecto: Create a case insensitive unique index

Today I learned that Ecto.Migration supports this out of the box 🥳

You probably know that you can easily create a unique index like this:

create unique_index("products", [:name], name: :products_lower_name_index)
Enter fullscreen mode Exit fullscreen mode

But did you also know that you can do this also in a case-insensitive way?
According to the docs you can not only provide column names for a new unique index, but also a custom expression.

# Create an index on a custom expression
create unique_index("products", ["(lower(name))"], name: :products_lower_name_index)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay