Fakultas Ilmu Komputer UI

seeds.exs 963 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
# Script for populating the database. You can run it as:
#
#     mix run priv/repo/seeds.exs
#
# Inside the script, you can read and write to any of your
# repositories directly:
#
#     Diskuy.Repo.insert!(%Diskuy.SomeSchema{})
#
# We recommend using the bang functions (`insert!`, `update!`
# and so on) as they will fail if something goes wrong.
Muhammad Rafif Elfazri's avatar
Muhammad Rafif Elfazri committed
12
13
alias Diskuy.Forum
alias Diskuy.Account
14
15
16
17




Muhammad Rafif Elfazri's avatar
Muhammad Rafif Elfazri committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{:ok, user} = Account.create_user(%{"username" => "admin",
                                    "email" => "admin@gmail.com",
                                    "picture" => "None"})
{:ok, topic} = Forum.create_topic(%{"name" => "random"})

Enum.each(0..200, fn(_x) ->
  Forum.create_thread(
    %{
      "title" => :crypto.strong_rand_bytes(32) |> Base.encode64 |> binary_part(0, 32),
      "points" => 0,
      "content" => :crypto.strong_rand_bytes(32) |> Base.encode64 |> binary_part(0, 32),
      "topic_id" => topic.id,
      "user_id" => user.id
    }
  )
  end)