🌱
Seeding
In seeds.ex we create an admin user and an arbitrary number of random users:
1
alias PetalPro.Accounts.User
2
alias PetalPro.Accounts.UserToken
3
alias PetalPro.Logs.Log
4
alias PetalPro.Accounts.UserSeeder
5
​
6
if Mix.env() == :dev do
7
PetalPro.Repo.delete_all(Log)
8
PetalPro.Repo.delete_all(UserToken)
9
PetalPro.Repo.delete_all(User)
10
​
11
UserSeeder.admin()
12
UserSeeder.random_users(20)
13
end
Copied!
We use the faker library for randomizing data:
1
def random_user_attributes(attrs \\ %{}) do
2
Enum.into(attrs, %{
3
name: Faker.Person.En.first_name() <> " " <> Faker.Person.En.last_name(),
4
email: unique_user_email()
5
})
6
end
Copied!
Seeds should be regularly updated with any new tables you create. This allows you to better test and develop your app.
Copy link