Skip to content
Permalink
Browse files

Code for step 7

  • Loading branch information
akoutmos committed Dec 5, 2019
1 parent 2491d6f commit d8d0fd85838dc94996b1745b18308cd84f8f8e74
Showing with 38 additions and 0 deletions.
  1. +20 −0 lib/hn_stats.ex
  2. +18 −0 priv/repo/migrations/20191205052229_create_stats_table.exs
@@ -0,0 +1,20 @@
defmodule ElixirPopularity.HNStats do
use Ecto.Schema
import Ecto.Changeset

schema "hn_stats" do
field(:item_id, :string)
field(:item_type, :string)
field(:language, :string)
field(:date, :date)
field(:occurances, :integer)
end

def changeset(hn_stats, params \\ %{}) do
all_fields = ~w(item_id item_type language date occurances)a

hn_stats
|> cast(params, all_fields)
|> validate_required(all_fields)
end
end
@@ -0,0 +1,18 @@
defmodule ElixirPopularity.Repo.Migrations.CreateStatsTable do
use Ecto.Migration

def change do
create table(:hn_stats) do
add(:item_id, :string)
add(:item_type, :string)
add(:language, :string)
add(:date, :date)
add(:occurances, :integer)
end

create(index(:hn_stats, [:date]))
create(index(:hn_stats, [:language]))
create(index(:hn_stats, [:item_id]))
create(index(:hn_stats, [:item_type]))
end
end

0 comments on commit d8d0fd8

Please sign in to comment.
You can’t perform that action at this time.