diff --git a/.env.erb b/.env.erb index 270fb7af..9d9f8cde 100644 --- a/.env.erb +++ b/.env.erb @@ -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 %> diff --git a/db/seeds.rb b/db/seeds.rb index 902b5428..167dfafc 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -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: "rob@example.com", current_company: goinvo) - juhan = User.build(name: "Juhan", email: "juhan@example.com", 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), @@ -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,