Skip to content

Commit

Permalink
Create restaurant schema
Browse files Browse the repository at this point in the history
  • Loading branch information
erickmp07 committed Sep 22, 2021
1 parent 2f3b044 commit e47fb1e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/inmana/restaurant.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
defmodule Inmana.Restaurant do
use Ecto.Schema
import Ecto.Changeset

@primary_key {:id, :binary_id, autogenerate: true}

schema "restaurants" do
field :email, :string
field :name, :string

timestamps()
end

def changeset(params) do
%__MODULE__{}
|> cast(params, [:email, :name])
|> validate_required([:email, :name])
|> validate_length(:name, min: 2)
|> validate_format(:email, ~r/@/)
|> unique_constraint([:email])
end
end

0 comments on commit e47fb1e

Please sign in to comment.