Main Website
Downloads
Roadmap
Community
Searchβ¦
v1.1.1
πΈ
What is Petal Pro?
Guides
π
Creating a web app from start to finish
Fundamentals
π₯
Users & Authentication
π
Included Pages
π§
Components
π¨
Branding
π±
Seeding
π
Layouts & Menus
π
Background Tasks and Jobs
π§
Util, DB & Helpers
π§
Emails
πͺ
Javascript Hooks
π
Extra Hex Libraries
π
Generators & Page Builder
π£
Translations
Powered By
GitBook
π±
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.
Fundamentals - Previous
Branding
Next - Fundamentals
Layouts & Menus
Last modified
2mo ago
Copy link