Added database data structures for processing and validating database table updates
This commit is contained in:
28
lib/sukaato/post.ex
Normal file
28
lib/sukaato/post.ex
Normal file
@@ -0,0 +1,28 @@
|
||||
defmodule Sukaato.Post do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
# import Sukaato.CustomValidators
|
||||
|
||||
schema "posts" do
|
||||
field :title, :string
|
||||
field :cat, :string
|
||||
field :abst, :string
|
||||
field :slug, :string
|
||||
field :content, :string
|
||||
field :tags, {:array, :string}
|
||||
field :ledit, :utc_datetime
|
||||
field :auth_id, :id
|
||||
field :rev_id, :id
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
end
|
||||
|
||||
@doc false
|
||||
def changeset(post, attrs) do
|
||||
post
|
||||
|> cast(attrs, [:title, :abst, :slug, :content, :tags, :cat, :ledit])
|
||||
|> validate_required([:title, :slug, :content, :cat, :ledit])
|
||||
|> validate_format(:cat, ~r/^(\.(\w)+)+/)
|
||||
|> unique_constraint(:title)
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user