Seeding means populating the database with records. We do this in development to show what the web app looks like with data.
alias PetalPro.Accounts.User
alias PetalPro.Accounts.UserSeeder
alias PetalPro.Accounts.UserToken
alias PetalPro.Accounts.UserTOTP
alias PetalPro.Files.FileSeeder
alias PetalPro.Logs.Log
alias PetalPro.Orgs.Invitation
alias PetalPro.Orgs.Membership
alias PetalPro.Orgs.Org
alias PetalPro.Orgs.OrgSeeder
alias PetalPro.Posts.Post
alias PetalPro.Posts.PostSeeder
if Mix.env() == :dev do
PetalPro.Repo.delete_all(Log)
PetalPro.Repo.delete_all(UserTOTP)
PetalPro.Repo.delete_all(Invitation)
PetalPro.Repo.delete_all(Membership)
PetalPro.Repo.delete_all(Org)
PetalPro.Repo.delete_all(UserToken)
PetalPro.Repo.delete_all(User)
PetalPro.Repo.delete_all(Post)
admin = UserSeeder.admin()
normal_user =
UserSeeder.normal_user(%{
email: "user@example.com",
name: "Sarah Cunningham",
password: "password",
confirmed_at: Timex.to_naive_datetime(DateTime.utc_now())
})
UserSeeder.fake_subscription(normal_user)
org = OrgSeeder.random_org(admin)
PetalPro.Orgs.create_invitation(org, %{email: normal_user.email})
UserSeeder.random_users(20)
FileSeeder.create_files(admin)
PostSeeder.create_posts(admin)
end
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.