Skip to content

Commit 73a3ad3

Browse files
Add eight cards to database
1 parent 9f94662 commit 73a3ad3

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

lib/pointing_party/card.ex

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
defmodule PointingParty.Card do
2+
use Ecto.Schema
3+
import Ecto.Changeset
4+
5+
schema "cards" do
6+
field :description, :string
7+
field :title, :string
8+
9+
timestamps()
10+
end
11+
12+
@doc false
13+
def changeset(card, attrs) do
14+
card
15+
|> cast(attrs, [:title, :description])
16+
|> validate_required([:title, :description])
17+
end
18+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
defmodule PointingParty.Repo.Migrations.CreateCards do
2+
use Ecto.Migration
3+
4+
def change do
5+
create table(:cards) do
6+
add :title, :string
7+
add :description, :string
8+
9+
timestamps()
10+
end
11+
12+
end
13+
end

priv/repo/seeds.exs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,23 @@
99
#
1010
# We recommend using the bang functions (`insert!`, `update!`
1111
# and so on) as they will fail if something goes wrong.
12+
13+
14+
alias PointingParty.{Card, Repo}
15+
16+
cards = [
17+
%{title: "First card", description: "This is a description of the first card."},
18+
%{title: "Second card", description: "This is a description of the second card."},
19+
%{title: "Third card", description: "This is a description of the third card."},
20+
%{title: "Fourth card", description: "This is a description of the fourth card."},
21+
%{title: "Fifth card", description: "This is a description of the fifth card."},
22+
%{title: "Sixth card", description: "This is a description of the sixth card."},
23+
%{title: "Seventh card", description: "This is a description of the seventh card."},
24+
%{title: "Eighth card", description: "This is a description of the eighth card."},
25+
]
26+
27+
Enum.each(cards, fn card ->
28+
%Card{}
29+
|> Card.changeset(card)
30+
|> Repo.insert!([])
31+
end)

0 commit comments

Comments
 (0)