File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change 9
9
#
10
10
# We recommend using the bang functions (`insert!`, `update!`
11
11
# 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 )
You can’t perform that action at this time.
0 commit comments