Case insensitive column

In Postgres, users can define case insensitive column by using the citext extension

In Postgres, users can define case insensitive column by using the :citext type/extension. Postgres documentation


CREATE TABLE users (
    email CITEXT PRIMARY KEY,
    pass TEXT   NOT NULL
);

Elixir, Postgres

In your migration: file for an Elixir application, you could add the following to make the email case-sensitiveness.

execute "CREATE EXTENSION IF NOT EXISTS citext"

create table(:users) do
  ...
  add :email, :citext
  ...
end

This means your Postgres DB will perform a downcase()

If for some reason your database does not support case insensitive columns, you can explicitly downcase values before inserting/updating them:

# Using elixir and ecto
cast(data, params, [:email])
|> update_change(:email, &String.downcase/1)
|> unique_constraint(:email)