Skip to content

Commit

Permalink
Bridge gap with Mirage seeds
Browse files Browse the repository at this point in the history
  • Loading branch information
joshsmith committed Jan 15, 2017
1 parent 2421e22 commit 99cb256
Showing 1 changed file with 155 additions and 19 deletions.
174 changes: 155 additions & 19 deletions priv/repo/seeds.exs
Original file line number Diff line number Diff line change
@@ -1,30 +1,51 @@
alias CodeCorps.{Category, Organization, OrganizationMembership, Project, ProjectCategory, ProjectSkill, Repo, Role, Skill, Task, User}
alias CodeCorps.{Category, Organization, OrganizationMembership, Project, ProjectCategory, ProjectSkill, Repo, Role, Skill, Task, User, UserCategory, UserRole, UserSkill}

# Users

users = [
%{
username: "adminstrator",
email: "admin@example.org",
email: "owner@codecorps.org",
first_name: "Code Corps",
last_name: "Owner",
password: "password",
admin: true
username: "codecorps-owner"
},
%{
username: "testuser",
email: "test@example.com",
password: "test123",
admin: false
email: "admin@codecorps.org",
first_name: "Code Corps",
last_name: "Admin",
password: "password",
username: "codecorps-admin"
},
%{
email: "contributor@codecorps.org",
first_name: "Code Corps",
last_name: "Contributor",
password: "password",
username: "codecorps-contributor"
},
%{
email: "pending@codecorps.org",
first_name: "Code Corps",
last_name: "Pending",
password: "password",
username: "codecorps-pending"
}
]

cond do
Repo.all(User) != [] ->
IO.puts "Users detected, aborting user seed."
true ->
Enum.each(users, fn user ->
%User{}
|> User.registration_changeset(user)
|> Repo.insert!
result =
%User{}
|> User.registration_changeset(user)
|> Repo.insert!

result
|> User.update_changeset(user)
|> Repo.update!
end)
end

Expand Down Expand Up @@ -287,7 +308,7 @@ cond do
number: i,
project_id: 1,
user_id: 1,
task_list_id: 1
task_list_id: Enum.random([1, 2, 3, 4])
})
|> Repo.insert!
end
Expand Down Expand Up @@ -321,12 +342,127 @@ cond do
Repo.all(OrganizationMembership) != [] ->
IO.puts "Organization memberships detected, aborting this seed."
true ->
owner = %{
organization_id: 1,
member_id: 1
}
contributors = [
%{
organization_id: 1,
member_id: 1,
role: "owner"
},
%{
organization_id: 1,
member_id: 2,
role: "admin"
},
%{
organization_id: 1,
member_id: 3,
role: "contributor"
},
%{
organization_id: 1,
member_id: 4,
role: "pending"
}
]

%OrganizationMembership{}
|> OrganizationMembership.create_owner_changeset(owner)
|> Repo.insert!
Enum.each(contributors, fn user ->
membership =
%OrganizationMembership{}
|> OrganizationMembership.create_changeset(user)
|> Repo.insert!

membership
|> OrganizationMembership.update_changeset(user)
|> Repo.update!
end)
end

cond do
Repo.all(UserCategory) != [] ->
IO.puts "User categories detected, aborting this seed."
true ->
user_categories = [
%{
category_id: 1,
user_id: 1
},
%{
category_id: 1,
user_id: 2
},
%{
category_id: 1,
user_id: 3
},
%{
category_id: 1,
user_id: 4
}
]

Enum.each(user_categories, fn user_category ->
%UserCategory{}
|> UserCategory.create_changeset(user_category)
|> Repo.insert!
end)
end

cond do
Repo.all(UserRole) != [] ->
IO.puts "User roles detected, aborting this seed."
true ->
user_roles = [
%{
role_id: 1,
user_id: 1
},
%{
role_id: 1,
user_id: 2
},
%{
role_id: 1,
user_id: 3
},
%{
role_id: 1,
user_id: 4
}
]

Enum.each(user_roles, fn user_role ->
%UserRole{}
|> UserRole.create_changeset(user_role)
|> Repo.insert!
end)
end

cond do
Repo.all(UserSkill) != [] ->
IO.puts "User skills detected, aborting this seed."
true ->
user_skills = [
%{
skill_id: 1,
user_id: 1
},
%{
skill_id: 1,
user_id: 2
},
%{
skill_id: 1,
user_id: 3
},
%{
skill_id: 1,
user_id: 4
}
]

Enum.each(user_skills, fn user_skill ->
%UserSkill{}
|> UserSkill.create_changeset(user_skill)
|> Repo.insert!
end)
end

0 comments on commit 99cb256

Please sign in to comment.