From e47fb1e138e2b8f02620bfe4960eebd113deacce Mon Sep 17 00:00:00 2001 From: Erick Macedo Pinto Date: Wed, 22 Sep 2021 09:04:16 -0300 Subject: [PATCH] Create restaurant schema --- lib/inmana/restaurant.ex | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 lib/inmana/restaurant.ex diff --git a/lib/inmana/restaurant.ex b/lib/inmana/restaurant.ex new file mode 100644 index 0000000..f0fa5db --- /dev/null +++ b/lib/inmana/restaurant.ex @@ -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