diff --git a/priv/repo/seeds.exs b/priv/repo/seeds.exs index 06f0d7e5b..9435c2586 100644 --- a/priv/repo/seeds.exs +++ b/priv/repo/seeds.exs @@ -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}") diff --git a/priv/repo/seeds/speakers.exs b/priv/repo/seeds/speakers.exs new file mode 100644 index 000000000..52c2eb904 --- /dev/null +++ b/priv/repo/seeds/speakers.exs @@ -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()