Ecto unique index not working?

In my migration for a PostGres table, I have something like this:

  def change do
    create table(:addresses) do
      add :street1, :string, size: 250, null: false
      add :street2, :string, size: 250, null: false
      add :city, :string, size: 100, null: false
      add :state, :string, size: 2, null: false
      add :zip, :string, size: 32, null: false
      add :country, :string, size: 3, null: false
      add :fingerprint, :string, size: 32, null: false
      timestamps()

    end

    # This does not work:
    unique_index(:addresses, [:fingerprint])
    # This does work
    # create index(:addresses, [:fingerprint], unique: true)

  end

The unique_index() function does not appear to be working… when I drop/create/migrate my table, I can inspect it inside of PostGres via \d Addresses and I can see immediately that no index was created.

However, if I use the create index() function instead, it works.

Is this a bug in Ecto? Or did mess up the syntax?

You need the create … for both functions.

5 Likes