webring/apps/webring/lib/webring/site.ex

23 lines
538 B
Elixir

defmodule Webring.Site do
use Ecto.Schema
import Ecto.Changeset
schema "sites" do
field(:url, :string)
field(:owner, :string)
field(:description, :string)
field(:title, :string)
field(:removal, :string)
timestamps()
end
def changeset(site, params \\ %{}) do
site
|> cast(params, [:url, :owner, :description, :title, :removal])
|> validate_format(:owner, ~r/@/)
|> validate_required([:owner, :title, :removal])
|> unique_constraint(:url)
|> unique_constraint(:removal)
end
end