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

23
lib/sukaato/comment.ex Normal file
View File

@@ -0,0 +1,23 @@
defmodule Sukaato.Comment do
use Ecto.Schema
import Ecto.Changeset
schema "comments" do
field :slug, :string
field :tripcode, :string
field :content, :string
field :ledit, :utc_datetime
field :post_id, :id
field :reply_to, :id
timestamps(type: :utc_datetime)
end
@doc false
def changeset(comment, attrs) do
comment
|> cast(attrs, [:slug, :tripcode, :content, :ledit])
|> validate_required([:slug, :tripcode, :content, :ledit])
|> unique_constraint(:tripcode)
end
end

24
lib/sukaato/folio.ex Normal file
View File

@@ -0,0 +1,24 @@
defmodule Sukaato.Folio do
use Ecto.Schema
import Ecto.Changeset
import Sukaato.Vschemas
import Sukaato.CustomValidators
schema "folios" do
field :resume, :map
field :showcase, :map
field :theme_uri, :string
field :user_id, :id
timestamps(type: :utc_datetime)
end
@doc false
def changeset(folio, attrs) do
folio
|> cast(attrs, [:resume, :showcase, :theme_uri])
|> validate_required([:user_id, :showcase])
|> validate_map_format(:resume, @resume_vschema)
|> validate_map_format(:showcase, @showcase_vschema)
end
end

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

36
lib/sukaato/user.ex Normal file
View File

@@ -0,0 +1,36 @@
defmodule Sukaato.User do
use Ecto.Schema
import Ecto.Changeset
alias Sukaato.Vschemas
import Sukaato.CustomValidators
schema "users" do
field :name, :string
field :password, :string
field :username, :string
field :email, :string
field :dob, :date
field :gender_type, Ecto.Enum, values: [:trans, :cis, :nb]
field :gender_id, Ecto.Enum, values: [:fem, :masc, :combined, :fluid, :none]
field :bio, :string
field :affil, {:array, :map}
field :perms, {:array, :integer}
field :user_token, :string
field :pub_keys, :map
timestamps(type: :utc_datetime)
end
@doc false
def changeset(user, attrs) do
user
|> cast(attrs, [:name, :username, :password, :email, :dob, :gender_type, :gender_id, :bio, :affil, :perms, :user_token, :pub_keys])
|> validate_required([:username, :password, :email, :dob, :perms, :user_token])
|> validate_length(:perms, is: 6)
|> validate_format(:email, ~r/@/)
|> validate_map_format(:perms, @perms_vschema)
|> validate_map_format(:affil, @affil_vschema)
|> validate_map_format(:pub_keys, @pubkeys_vschema)
|> unique_constraint(:username)
end
end