🌱Seeding

In seeds.ex we create an admin user and an arbitrary number of random users:

alias PetalPro.Accounts.User
alias PetalPro.Accounts.UserToken
alias PetalPro.Logs.Log
alias PetalPro.Accounts.UserSeeder

if Mix.env() == :dev do
  PetalPro.Repo.delete_all(Log)
  PetalPro.Repo.delete_all(UserToken)
  PetalPro.Repo.delete_all(User)

  UserSeeder.admin()
  UserSeeder.random_users(20)
end

We use the faker library for randomizing data:

def random_user_attributes(attrs \\ %{}) do
  Enum.into(attrs, %{
    name: Faker.Person.En.first_name() <> " " <> Faker.Person.En.last_name(),
    email: unique_user_email()
  })
end

Seeds should be regularly updated with any new tables you create. This allows you to better test and develop your app.

Last updated