diff --git a/lib/app/list.ex b/lib/app/list.ex new file mode 100644 index 00000000..94a2ef06 --- /dev/null +++ b/lib/app/list.ex @@ -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 diff --git a/lib/app/list_items.ex b/lib/app/list_items.ex new file mode 100644 index 00000000..5465e9e7 --- /dev/null +++ b/lib/app/list_items.ex @@ -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 diff --git a/priv/repo/migrations/20220627162154_create_items.exs b/priv/repo/migrations/20220627162154_create_items.exs index 904a2172..af518729 100644 --- a/priv/repo/migrations/20220627162154_create_items.exs +++ b/priv/repo/migrations/20220627162154_create_items.exs @@ -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 diff --git a/priv/repo/migrations/20230416001029_create_lists.exs b/priv/repo/migrations/20230416001029_create_lists.exs new file mode 100644 index 00000000..03679254 --- /dev/null +++ b/priv/repo/migrations/20230416001029_create_lists.exs @@ -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 diff --git a/priv/repo/migrations/20230416001045_create_list_items.exs b/priv/repo/migrations/20230416001045_create_list_items.exs new file mode 100644 index 00000000..c6d414d5 --- /dev/null +++ b/priv/repo/migrations/20230416001045_create_list_items.exs @@ -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