Is it possible to make Ecto Values unique?

As @Ankhers pointed out, you can make a migration that will create an unique constraint on the desired column. Let’s say your table is named entities and the column you want to be unique ip.

def change do
    create unique_index(:entities, [:ip])
end

Then in the Ecto changeset you use for insertion, you will have to add that unique constraint so on duplicated insertion attempt an error will be returned.

def changeset(entity, attrs) do
    entities
    |> cast(attrs, [...])
    |> validate_required([...])
    |> unique_constraint(:ip, message: "This ip is already recorded!")
end

Hope this helps.

Edit:

Of course in some controller you can check if an insertion failed due to that unique constraint and then do specific action or just nothing. ^^

Edit 2:
This thread may be interresting to you if from the place you’re trying to insert your record, you need to pattern match the unique constraint error.