super-graph/rails-app/db/seeds.rb

96 lines
2.1 KiB
Ruby
Raw Normal View History

2019-03-24 14:57:29 +01:00
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
pwd = "123456"
user_count = 10
customer_count = 100
product_count = 50
purchase_count = 100
2019-04-09 14:43:42 +02:00
3.times do |i|
user = User.create(
full_name: Faker::Name.name,
avatar: Faker::Avatar.image,
phone: Faker::PhoneNumber.cell_phone,
2019-04-11 07:10:51 +02:00
email: "user#{i}@demo.com",
2019-04-09 14:43:42 +02:00
password: pwd,
password_confirmation: pwd
)
user.save!
puts user.inspect
end
2019-03-24 14:57:29 +01:00
user_count.times do |i|
user = User.create(
full_name: Faker::Name.name,
avatar: Faker::Avatar.image,
phone: Faker::PhoneNumber.cell_phone,
email: Faker::Internet.email,
password: pwd,
password_confirmation: pwd
)
user.save!
puts user.inspect
end
customer_count.times do |i|
customer = Customer.create(
full_name: Faker::Name.name,
phone: Faker::PhoneNumber.cell_phone,
email: Faker::Internet.email,
password: pwd,
password_confirmation: pwd
)
customer.save!
puts customer.inspect
end
product_count.times do |i|
desc = [
Faker::Beer.brand,
Faker::Beer.style,
Faker::Beer.hop,
Faker::Beer.yeast,
Faker::Beer.ibu,
Faker::Beer.alcohol,
Faker::Beer.blg,
].join(", ")
product = Product.create(
name: Faker::Beer.name,
description: desc,
price: rand(5.5..19.0),
user_id: rand(1..user_count)
)
product.save!
puts product.inspect
end
purchase_count.times do |i|
sale_type = ["rented", "bought"].sample
if sale_type == "rented"
due_date = Faker::Date.forward(30)
if [0, 3].sample == 1
returned = Faker::Date.forward(60)
end
end
purchase = Purchase.create(
customer_id: rand(1..customer_count),
product_id: rand(1..product_count),
sale_type: sale_type,
quantity: rand(1..10),
due_date: due_date,
returned: returned
)
purchase.save!
puts purchase.inspect
end