Added database data structures for processing and validating database table updates

This commit is contained in:
Alex Tavarez
2025-07-25 11:34:30 -04:00
parent 8eeeee3090
commit e1a9f32c21
4 changed files with 111 additions and 0 deletions

28
lib/sukaato/post.ex Normal file
View 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