Today I Learned

A Hashrocket project

Ready to join Hashrocket? Find Openings here and apply today.

Conditional unique index with Ecto

I was going to create a conditional index using raw sql like this:

create unique index posts_name_index on posts (name) where deleted_at is null;

But then I learned that you can use the where option with create unique_index:

create unique_index(:posts, [:name], where: "deleted_at is null")
Looking for help? At Hashrocket, we 💜 Elixir! From our many Elixir client projects, to sponsoring the Chicago Elixir Meetup, to the source code for this application, we are invested in this community. Contact us today to talk about your Elixir project.