built basic ui structure in /hierarchy
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
defmodule RiverConnect.Repo.Migrations.CreateHierarchy do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:springs) do
|
||||
add :name, :string, null: false
|
||||
# :dm, :job, :custom
|
||||
add :type, :string, null: false
|
||||
add :description, :text
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
create table(:rivers) do
|
||||
add :name, :string, null: false
|
||||
add :description, :text
|
||||
add :spring_id, references(:springs, on_delete: :delete_all), null: false
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
create index(:rivers, [:spring_id])
|
||||
|
||||
create table(:streams) do
|
||||
add :name, :string, null: false
|
||||
add :topic, :string
|
||||
add :river_id, references(:rivers, on_delete: :delete_all), null: false
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
create index(:streams, [:river_id])
|
||||
|
||||
create table(:trenches) do
|
||||
add :name, :string
|
||||
add :stream_id, references(:streams, on_delete: :delete_all), null: false
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
create index(:trenches, [:stream_id])
|
||||
end
|
||||
end
|
||||
@@ -1,11 +1,73 @@
|
||||
# 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:
|
||||
#
|
||||
# RiverConnect.Repo.insert!(%RiverConnect.SomeSchema{})
|
||||
#
|
||||
# We recommend using the bang functions (`insert!`, `update!`
|
||||
# and so on) as they will fail if something goes wrong.
|
||||
actions = [
|
||||
fn ->
|
||||
alias RiverConnect.Hierarchy
|
||||
alias RiverConnect.Repo
|
||||
|
||||
# 1. Create DM Spring
|
||||
case Repo.get_by(Hierarchy.Spring, name: "Direct Messages") do
|
||||
nil ->
|
||||
{:ok, spring} =
|
||||
Hierarchy.create_spring(%{
|
||||
name: "Direct Messages",
|
||||
type: "dm",
|
||||
description: "Private conversations between users"
|
||||
})
|
||||
|
||||
IO.puts("Created 'Direct Messages' Spring")
|
||||
spring
|
||||
|
||||
spring ->
|
||||
IO.puts("'Direct Messages' Spring already exists")
|
||||
spring
|
||||
end
|
||||
|
||||
# 2. Create Jobs Spring
|
||||
{:ok, jobs_spring} =
|
||||
case Repo.get_by(Hierarchy.Spring, name: "Jobs") do
|
||||
nil ->
|
||||
{:ok, spring} =
|
||||
Hierarchy.create_spring(%{
|
||||
name: "Jobs",
|
||||
type: "job",
|
||||
description: "Job-specific rivers"
|
||||
})
|
||||
|
||||
IO.puts("Created 'Jobs' Spring")
|
||||
{:ok, spring}
|
||||
|
||||
spring ->
|
||||
IO.puts("'Jobs' Spring already exists")
|
||||
{:ok, spring}
|
||||
end
|
||||
|
||||
# 3. Create a sample River in Jobs
|
||||
case Repo.get_by(Hierarchy.River, name: "General Construction", spring_id: jobs_spring.id) do
|
||||
nil ->
|
||||
{:ok, river} =
|
||||
Hierarchy.create_river(%{
|
||||
name: "General Construction",
|
||||
description: "General discussions about construction jobs",
|
||||
spring_id: jobs_spring.id
|
||||
})
|
||||
|
||||
IO.puts("Created 'General Construction' River")
|
||||
|
||||
# 4. Create sample Stream
|
||||
{:ok, _stream} =
|
||||
Hierarchy.create_stream(%{
|
||||
name: "Announcements",
|
||||
topic: "Important announcements",
|
||||
river_id: river.id
|
||||
})
|
||||
|
||||
IO.puts("Created 'Announcements' Stream")
|
||||
|
||||
_ ->
|
||||
IO.puts("'General Construction' River already exists")
|
||||
end
|
||||
end
|
||||
]
|
||||
|
||||
for action <- actions do
|
||||
action.()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user