-
-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathseeds.rb
More file actions
106 lines (92 loc) · 4.44 KB
/
seeds.rb
File metadata and controls
106 lines (92 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
time =
Benchmark.measure do
if Rails.env.development?
ActiveRecord::Base.logger.silence do
begin
Rails.logger.info 'Running migrations...'
Rails.application.config.log_level = :info
Rails.logger.info "Creating chapters..."
chapters = ['London', 'Brighton', 'Cambridge', 'Barcelona', 'Paris', 'Merlbourne', 'Berlin', 'New York'].map do |name|
Fabricate(:chapter_with_groups, name: name)
end
Rails.logger.info "Creating workshops..."
number_of_workshops = ENV["SEED_HIGH_VOLUME_OF_WORKSHOPS"] ? 10_000 : 6
workshops = number_of_workshops.times.map do |n|
start = Time.zone.now + 1.month - n.weeks
ends_at = start + 3.hours
Fabricate(:workshop, title: 'Workshop',
chapter: chapters.sample,
date_and_time: start,
ends_at: ends_at)
end
workshops.concat Fabricate.times(2, :workshop, title: 'Workshop', chapter: chapters.sample)
Rails.logger.info "Creating a lot of old workshops..."
number_of_past_workshops = ENV["SEED_HIGH_VOLUME_OF_WORKSHOPS"] ? 40 : 5
past_workshops_since_n_months = number_of_past_workshops * 12
past_workshops_one_per_n_months = 6
past_workshops_count = past_workshops_since_n_months/past_workshops_one_per_n_months
past_workshops = past_workshops_count.times.map do |n|
Fabricate(:workshop, title: 'Workshop',
chapter: chapters.sample,
date_and_time: Time.zone.now - past_workshops_since_n_months.months + (past_workshops_one_per_n_months * n).months
)
end
Rails.logger.info "Creating events..."
events = 2.times.map do |n|
Fabricate(:event, name: 'Event',
chapters: chapters.sample(4),
date_and_time: Time.zone.now + 2.months - n.months)
end
Rails.logger.info "Creating meetings..."
2.times.map do |n|
Fabricate(:meeting, name: 'Meeting',
date_and_time: Time.zone.now + 1.month - n.months)
end
Rails.logger.info "Creating coaches..."
coaches = 50.times.map { Fabricate(:coach, groups: Group.coaches.order('RANDOM()').limit(2)) }
tutorials = Fabricate.times(20, :tutorial)
30.times { Fabricate(:feedback_request, workshop: past_workshops.sample) }
20.times { Fabricate(:feedback, tutorial: tutorials.sample, coach: coaches.sample) }
10.times { Fabricate(:testimonial, member: coaches.sample) }
job_titles = [
'Software Engineer',
'Software Developer',
'Front-end Developer',
'Back-end Developer',
'Full-stack Developer'
]
job_companies = %w[
ACME
Globex
Soylent
Initech
Umbrella
Wonka
]
Rails.logger.info "Creating students..."
students = 50.times.map { Fabricate(:student, groups: Group.students.order('RANDOM()').limit(2)) }
Rails.logger.info "Creating event invitations..."
2.times do |n|
Fabricate(:invitation, member: students.sample, event: events.sample)
Fabricate(:coach_invitation, member: coaches.sample, event: events.sample)
end
Rails.logger.info "Creating attended by coach workshop invitations..."
coaches.sample(15).each do |coach|
past_workshops.sample(3).each do |workshop|
Fabricate(:attended_coach, workshop: workshop, member: coach)
end
end
Rails.logger.info "Creating workshop invitations..."
30.times do |n|
Fabricate(:coach_workshop_invitation, member: coaches.sample, workshop: workshops.sample) rescue nil
Fabricate(:student_workshop_invitation, member: students.sample, workshop: workshops.sample) rescue nil
end
Rails.logger.info '..done!'
rescue Exception => e
Rails.logger.error 'Something went wrong. Try running `bundle exec rake db:drop db:create db:migrate` first'
Rails.logger.error e.message
end
end
end
end
Rails.logger.info("✅ Done. Seeding took #{time.real.round(2)} seconds.")