Last active
September 22, 2016 19:48
-
-
Save Ivor/815f9128fc73b162118dd6cdcc0b48e9 to your computer and use it in GitHub Desktop.
Ecto migration with unique_index on multiple fields.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule VetMapper.Repo.Migrations.BranchesStreetAddressUniqueConstraint do | |
use Ecto.Migration | |
def up do | |
create unique_index(:branches, [:country, :state, :city, :street_name, :street_number], name: :index_branches_on_address) | |
end | |
def down do | |
drop index(:branches, [:country, :state, :city, :street_name, :street_number], name: :index_branches_on_address) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mock models can be found here: https://gist.github.com/Ivor/6c59b45e2aa982b13e27e06fc486b3f2
Blog post: https://medium.com/@ivorpaul/ecto-how-to-validate-unique-combinations-of-multiple-fields-8002c74c6757#.f1iwh3dzf