Skip to content

Commit

Permalink
create lists and list_items schemas for #145 ref: dwyl/app#271
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Apr 16, 2023
1 parent 82934f6 commit 35bf05c
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
19 changes: 19 additions & 0 deletions lib/app/list.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
defmodule App.List do
use Ecto.Schema
import Ecto.Changeset

schema "lists" do
field :person_id, :integer
field :status, :integer
field :text, :string

timestamps()
end

@doc false
def changeset(list, attrs) do
list
|> cast(attrs, [:person_id, :status, :text])
|> validate_required([:person_id, :status, :text])
end
end
20 changes: 20 additions & 0 deletions lib/app/list_items.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
defmodule App.ListItems do
use Ecto.Schema
import Ecto.Changeset

schema "list_items" do
field :person_id, :integer
field :position, :float
field :item_id, :id
field :list_id, :id

timestamps()
end

@doc false
def changeset(list_items, attrs) do
list_items
|> cast(attrs, [:person_id, :position])
|> validate_required([:person_id, :position])
end
end
1 change: 0 additions & 1 deletion priv/repo/migrations/20220627162154_create_items.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ defmodule App.Repo.Migrations.CreateItems do
add(:text, :string)
add(:person_id, :integer)
add(:status, :integer)
add(:position, :integer)

timestamps()
end
Expand Down
13 changes: 13 additions & 0 deletions priv/repo/migrations/20230416001029_create_lists.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
defmodule App.Repo.Migrations.CreateLists do
use Ecto.Migration

def change do
create table(:lists) do
add :person_id, :integer
add :status, :integer
add :text, :string

timestamps()
end
end
end
17 changes: 17 additions & 0 deletions priv/repo/migrations/20230416001045_create_list_items.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
defmodule App.Repo.Migrations.CreateListItems do
use Ecto.Migration

def change do
create table(:list_items) do
add :person_id, :integer
add :position, :float
add :item_id, references(:items, on_delete: :nothing)
add :list_id, references(:lists, on_delete: :nothing)

timestamps()
end

create index(:list_items, [:item_id])
create index(:list_items, [:list_id])
end
end

0 comments on commit 35bf05c

Please sign in to comment.