Skip to content

Commit

Permalink
Merge branch 'develop' into dp/add-new-activity-form
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsp45 committed Sep 19, 2023
2 parents 01068c1 + dfd1184 commit 2720eb3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion priv/repo/seeds.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ defmodule Atomic.Repo.Seeds do
"activities.exs",
"memberships.exs",
"announcements.exs",
"partners.exs"
"partners.exs",
"speakers.exs"
]
|> Enum.each(fn file ->
Code.require_file("#{@seeds_dir}/#{file}")
Expand Down
37 changes: 37 additions & 0 deletions priv/repo/seeds/speakers.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
defmodule Atomic.Repo.Seeds.Speakers do
@moduledoc """
Seeds the database with speakers.
"""
alias Atomic.Activities
alias Atomic.Activities.Speaker
alias Atomic.Organizations.Organization
alias Atomic.Repo

@organizations Repo.all(Organization)

def run do
case Repo.all(Speaker) do
[] ->
seed_speakers()

_ ->
Mix.shell().error("Found speakers, aborting seeding speakers.")
end
end

def seed_speakers do
for _ <- 0..30 do
organization = Enum.random(@organizations)

attrs = %{
"name" => Faker.Person.name(),
"bio" => Faker.Lorem.sentence(),
"organization_id" => organization.id
}

Activities.create_speaker(attrs)
end
end
end

Atomic.Repo.Seeds.Speakers.run()

0 comments on commit 2720eb3

Please sign in to comment.