-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
creates emotion_log table with enum type for emotion #22
- Loading branch information
1 parent
0b5a49e
commit 77a9ef4
Showing
5 changed files
with
39 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,3 @@ | ||
import EctoEnum | ||
|
||
defenum Afc.EctoEnum.EmotionEnum, :emotion, [:angry, :happy] |
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 Afc.EmotionLog do | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
alias Afc.EctoEnum.EmotionEnum | ||
|
||
schema "emotion_logs" do | ||
field :emotion, EmotionEnum | ||
field :user_id, :id | ||
|
||
timestamps() | ||
end | ||
|
||
@doc false | ||
def changeset(emotion_log, attrs) do | ||
emotion_log | ||
|> cast(attrs, [:emotion]) | ||
|> validate_required([:emotion]) | ||
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
14 changes: 14 additions & 0 deletions
14
priv/repo/migrations/20181015111921_create_emotion_logs.exs
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,14 @@ | ||
defmodule Afc.Repo.Migrations.CreateEmotionLogs do | ||
use Ecto.Migration | ||
|
||
def change do | ||
create table(:emotion_logs) do | ||
add :emotion, :string | ||
add :user_id, references(:users, on_delete: :nothing) | ||
|
||
timestamps() | ||
end | ||
|
||
create index(:emotion_logs, [:user_id]) | ||
end | ||
end |