Skip to content

Commit

Permalink
create more seed data
Browse files Browse the repository at this point in the history
  • Loading branch information
fermion committed Dec 22, 2023
1 parent 0ecc021 commit 00a4331
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions .env.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
RAILS_MASTER_KEY=<%= `op read "op://StaffplanRedux/RAILS_MASTER_KEY/credential"`.strip %>
DOCKER_REGISTRY_TOKEN=<%= `op read "op://StaffplanRedux/KAMAL_REGISTRY_PASSWORD/credential"`.strip %>
POSTGRES_PASSWORD=<%= `op read "op://StaffplanRedux/POSTGRES_PASSWORD/credential"`.strip %>
STAFF_PLAN_EMAILS=<%= `op read "op://StaffplanRedux/STAFF_PLAN_EMAILS/credential"`.strip %>
<% else raise ArgumentError, "Session token missing" end %>
26 changes: 15 additions & 11 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,30 @@
# MovieGenre.find_or_create_by!(name: genre_name)
# end

# TODO: write a command object for this.

goinvo = Company.find_or_create_by(name: "GoInvo")
emails = ENV["STAFF_PLAN_EMAILS"].split(",").map(&:strip)

if goinvo.users.none?
rob = User.build(name: "Rob", email: "[email protected]", current_company: goinvo)
juhan = User.build(name: "Juhan", email: "[email protected]", current_company: goinvo)
goinvo.memberships.build(user: rob, role: "owner", status: 'active')
goinvo.memberships.build(user: juhan, role: "owner", status: 'active')
emails.each do |email|
AddUserToCompany.new(
email:,
name: Faker::Name.name,
company: goinvo
).call
end

goinvo.save!
else
puts "Found users for GoInvo, skipping..."
end

if goinvo.clients.none?
design_anonymous = goinvo.clients.create(name: "Design Anonymous")
builders_paradise = goinvo.clients.create(name: "Builder's Paradise")
5.times do
goinvo.clients.create(name: Faker::Company.name)
end

[design_anonymous, builders_paradise].each do |client|
5.times do
goinvo.clients.each do |client|
7.times do
client.projects.create(
name: Faker::Company.name,
cost: Faker::Number.decimal(l_digits: 2),
Expand All @@ -36,7 +40,7 @@
)
end

[rob, juhan].each do |user|
goinvo.users.each do |user|
client.projects.sample(2).each do |project|
Assignment.create!(
user: user,
Expand Down

0 comments on commit 00a4331

Please sign in to comment.