parent
177067ab00
commit
9af0124138
11 changed files with 608 additions and 60 deletions
16
priv/repo/migrations/20200809220758_create_plans.exs
Normal file
16
priv/repo/migrations/20200809220758_create_plans.exs
Normal file
|
@ -0,0 +1,16 @@
|
|||
defmodule Planner.Repo.Migrations.CreatePlans do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:plans, primary_key: false) do
|
||||
add :id, :binary_id, primary_key: true
|
||||
add :description, :string
|
||||
add :finished_at, :naive_datetime
|
||||
add :start, :naive_datetime
|
||||
add :end, :naive_datetime
|
||||
add :name, :string
|
||||
|
||||
timestamps()
|
||||
end
|
||||
end
|
||||
end
|
18
priv/repo/migrations/20200809221238_create_plan_details.exs
Normal file
18
priv/repo/migrations/20200809221238_create_plan_details.exs
Normal file
|
@ -0,0 +1,18 @@
|
|||
defmodule Planner.Repo.Migrations.CreatePlanDetails do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:plan_details, primary_key: false) do
|
||||
add :id, :binary_id, primary_key: true
|
||||
add :sort, :integer
|
||||
add :task_id, references(:tasks, on_delete: :nothing, type: :binary_id)
|
||||
add :plan_id, references(:plans, on_delete: :nothing, type: :binary_id)
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
create index(:plan_details, [:task_id])
|
||||
create index(:plan_details, [:plan_id])
|
||||
create unique_index(:plan_details, [:task_id, :plan_id])
|
||||
end
|
||||
end
|
|
@ -1,11 +1,46 @@
|
|||
# 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:
|
||||
#
|
||||
# Planner.Repo.insert!(%Planner.SomeSchema{})
|
||||
#
|
||||
# We recommend using the bang functions (`insert!`, `update!`
|
||||
# and so on) as they will fail if something goes wrong.
|
||||
# mix run priv/repo/seeds.exs
|
||||
|
||||
alias Planner.Tasks
|
||||
|
||||
tasks_records = [
|
||||
%{"value" => "task1"},
|
||||
%{"value" => "task2"},
|
||||
%{"value" => "task3"},
|
||||
%{"value" => "task4"},
|
||||
%{"value" => "task5"},
|
||||
%{"value" => "task6"}
|
||||
]
|
||||
|
||||
tasks =
|
||||
Enum.map(tasks_records, fn record ->
|
||||
{:ok, task} = Tasks.create_task(record)
|
||||
task
|
||||
end)
|
||||
|
||||
plans_records = [
|
||||
%{name: "plan1"},
|
||||
%{name: "plan2"},
|
||||
%{name: "plan3"}
|
||||
]
|
||||
|
||||
plans =
|
||||
Enum.map(plans_records, fn record ->
|
||||
{:ok, plan} = Tasks.create_plan(record)
|
||||
plan
|
||||
end)
|
||||
|
||||
[t1, t2, t3, t4, t5, _] = tasks
|
||||
[p1, p2, _] = plans
|
||||
|
||||
plan_details_records = [
|
||||
%{plan_id: p1.id, task_id: t1.id, sort: 0},
|
||||
%{plan_id: p1.id, task_id: t2.id, sort: 0},
|
||||
%{plan_id: p1.id, task_id: t3.id, sort: 0},
|
||||
%{plan_id: p2.id, task_id: t4.id, sort: 0},
|
||||
%{plan_id: p2.id, task_id: t5.id, sort: 0}
|
||||
# deliberately leave off the last task
|
||||
]
|
||||
|
||||
Enum.each(plan_details_records, fn record ->
|
||||
Tasks.create_plan_detail(record)
|
||||
end)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue