-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create lists and list_items schemas for #145 ref: dwyl/app#271
- Loading branch information
Showing
5 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |