Skip to content

Commit

Permalink
creates emotion_log table with enum type for emotion #22
Browse files Browse the repository at this point in the history
  • Loading branch information
RobStallion committed Oct 15, 2018
1 parent 0b5a49e commit 77a9ef4
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/afc/ecto_enum/ecto_enums.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import EctoEnum

defenum Afc.EctoEnum.EmotionEnum, :emotion, [:angry, :happy]
19 changes: 19 additions & 0 deletions lib/afc/emotion_log.ex
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
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ defmodule Afc.Mixfile do
{:cowboy, "~> 1.0"},
{:excoveralls, "~> 0.10", only: :test},
{:credo, "~> 0.10.0", only: [:dev, :test], runtime: false},
{:autoform, github: "dwyl/autoform"}
{:autoform, github: "dwyl/autoform"},
{:ecto_enum, "~> 1.0"}
]
end

Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"db_connection": {:hex, :db_connection, "1.1.3", "89b30ca1ef0a3b469b1c779579590688561d586694a3ce8792985d4d7e575a61", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
"decimal": {:hex, :decimal, "1.5.0", "b0433a36d0e2430e3d50291b1c65f53c37d56f83665b43d79963684865beab68", [:mix], [], "hexpm"},
"ecto": {:hex, :ecto, "2.2.11", "4bb8f11718b72ba97a2696f65d247a379e739a0ecabf6a13ad1face79844791c", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
"ecto_enum": {:hex, :ecto_enum, "1.1.0", "d44fe2ce6e1c0e907e7c3b6456a69e0f1d662348d8b4e2a662ba312223d8ff62", [:mix], [{:ecto, ">= 2.0.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, ">= 0.0.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, repo: "hexpm", optional: true]}], "hexpm"},
"excoveralls": {:hex, :excoveralls, "0.10.1", "407d50ac8fc63dfee9175ccb4548e6c5512b5052afa63eedb9cd452a32a91495", [:mix], [{:hackney, "~> 1.13", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
"file_system": {:hex, :file_system, "0.2.6", "fd4dc3af89b9ab1dc8ccbcc214a0e60c41f34be251d9307920748a14bf41f1d3", [:mix], [], "hexpm"},
"gettext": {:hex, :gettext, "0.16.0", "4a7e90408cef5f1bf57c5a39e2db8c372a906031cc9b1466e963101cb927dafc", [:mix], [], "hexpm"},
Expand Down
14 changes: 14 additions & 0 deletions priv/repo/migrations/20181015111921_create_emotion_logs.exs
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

0 comments on commit 77a9ef4

Please sign in to comment.