Commit 4a301b52 authored by Ahmad Sattar's avatar Ahmad Sattar

final touches on seed script and additions to the README accordingly

parent c7172daf
......@@ -35,6 +35,8 @@ mix deps.get # Get Hex dependencies, answer yes to installing Hex
mix compile # Compile application
mix ecto.create # Create database using default credentials
mix ecto.migrate # Migrate database to latest state
mix run priv/repo/seeds.exs # To initialize a test:test user for testing, inspect file
# for further tweaking (optional)
cd assets && npm install # Install frontend dependencies and tools
nano config/dev.secret.exs # Set up dev config with at least the line "use Mix.Config"
# at the top
......@@ -45,6 +47,7 @@ nano config/dev.secret.exs # Set up dev config with at least the line "use Mix.
* `mix test`: Run all tests suite
* `mix phx.server`: Run development server on port 5000 (default, you can configure this in
`dev.secret.exs`)
* `mix ecto.reset`: Shorthand for dropping, creating, migrating and running seed script
* `mix frontend.build`: Build the JS/CSS frontend
* `mix frontend.watch`: Build the frontend and watch for changes (also run when using `phx.server`)
* `mix frontend.clean`: Clean frontend output and build artifacts
......
......@@ -9,10 +9,16 @@
# This script creates a given user from the "user" map.
# You can change credentials as you wish below.
#
# This script can be run multiple times without overwriting existing date, just adding new.
# This means seeded data for multiple machines and multiple languages is easily done.
# Resetting the database can be done with
#
# mix ecto.reset
#
# In the "languages" list you can append/remove names of languages to populate.
# Every language will be populated for every day with the given range
# Every language will be populated for every day with the given range.
#
# In the "dates_xp" map self explainatory settings can be tweaked
# In the "dates_xp" map self explainatory settings can be tweaked.
# ------------
......@@ -24,13 +30,13 @@ initial_user = %{
terms_version: CodeStats.LegalTerms.get_latest_version()
}
initial_machine = "test_machine2"
initial_machine = "test_machine"
languages = ["elixir", "javascript"]
dates_and_xp = %{
"date_from" => {2018, 04, 01},
"date_to" => {2018, 06, 01},
"date_from" => {2018, 07, 01},
"date_to" => {2018, 08, 01},
"min" => 500,
"max" => 700,
"random_time" => true
......@@ -61,6 +67,20 @@ defmodule Seeds do
{:ok, fetched_user, machine}
end
defp create_new_user(user_map) do
{:ok, fetched_user} =
CodeStats.User.changeset(%CodeStats.User{}, user_map)
|> CodeStats.Repo.insert()
{:ok, machine} =
%CodeStats.User.Machine{name: "test_machine"}
|> CodeStats.User.Machine.changeset(%{})
|> Ecto.Changeset.put_change(:user_id, fetched_user.id)
|> CodeStats.Repo.insert()
{:ok, fetched_user, machine}
end
defp get_or_create_machine(user, machine_name) do
case CodeStats.Repo.get_by(CodeStats.User.Machine, user_id: user.id, name: machine_name) do
nil ->
......@@ -77,20 +97,6 @@ defmodule Seeds do
end
end
defp create_new_user(user_map) do
{:ok, fetched_user} =
CodeStats.User.changeset(%CodeStats.User{}, user_map)
|> CodeStats.Repo.insert()
{:ok, machine} =
%CodeStats.User.Machine{name: "test_machine"}
|> CodeStats.User.Machine.changeset(%{})
|> Ecto.Changeset.put_change(:user_id, fetched_user.id)
|> CodeStats.Repo.insert()
{:ok, fetched_user, machine}
end
defp create_date_list(%{"from" => in_from, "to" => in_to, "random_time" => random_time}) do
from = Calendar.DateTime.from_erl!({in_from, {16, 00, 00}}, "Etc/UTC")
to = Calendar.DateTime.from_erl!({in_to, {16, 00, 00}}, "Etc/UTC")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment