I'm writing a migration file and one of the fields I'd like to set a DB (Postgres) constraint for:
def change do
create table(:reviews) do
add(:title, :string)
add(:contents, :string)
add(:stars, :integer)
add(:user_id, references(:users), null: false)
add(:user_id, references(:users), null: false)
timestamps()
end
Id like to set a constraint on the stars field to be integer values only 1-5. How can I do this with Ecto.Migration?
Ecto.Migration.create(Ecto.Migration.constraint/3)
foo/priv/repo/migations/....create_reviews.exs:
foo/lib/foo/review.ex:
foo/lib/foo.ex:
In iex:
]