feat: first entities in database
This commit is contained in:
30
lib/bds/projects/project.ex
Normal file
30
lib/bds/projects/project.ex
Normal file
@@ -0,0 +1,30 @@
|
||||
defmodule BDS.Projects.Project do
|
||||
@moduledoc false
|
||||
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
@primary_key {:id, :string, autogenerate: false}
|
||||
@foreign_key_type :string
|
||||
|
||||
schema "projects" do
|
||||
field :name, :string
|
||||
field :slug, :string
|
||||
field :description, :string
|
||||
field :data_path, :string
|
||||
field :created_at, :integer
|
||||
field :updated_at, :integer
|
||||
field :is_active, :boolean, default: false
|
||||
|
||||
has_many :posts, BDS.Posts.Post, foreign_key: :project_id
|
||||
end
|
||||
|
||||
def changeset(project, attrs) do
|
||||
project
|
||||
|> cast(attrs, [:id, :name, :slug, :description, :data_path, :created_at, :updated_at, :is_active],
|
||||
empty_values: [nil]
|
||||
)
|
||||
|> validate_required([:id, :name, :slug, :created_at, :updated_at, :is_active])
|
||||
|> unique_constraint(:slug)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user