Optimize seeds file
This commit is contained in:
		
							parent
							
								
									a5d3062654
								
							
						
					
					
						commit
						b112aefe21
					
				
							
								
								
									
										50
									
								
								db/seeds.rb
									
									
									
									
									
								
							
							
						
						
									
										50
									
								
								db/seeds.rb
									
									
									
									
									
								
							@ -1,3 +1,5 @@
 | 
				
			|||||||
 | 
					# frozen_string_literal: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Copyright (C) 2024-2025 LibreWeddingPlanner contributors
 | 
					# Copyright (C) 2024-2025 LibreWeddingPlanner contributors
 | 
				
			||||||
 | 
					
 | 
				
			||||||
NUMBER_OF_GUESTS = 50
 | 
					NUMBER_OF_GUESTS = 50
 | 
				
			||||||
@ -9,20 +11,22 @@ end
 | 
				
			|||||||
wedding = Wedding.create!(slug: :default)
 | 
					wedding = Wedding.create!(slug: :default)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ActsAsTenant.with_tenant(wedding) do
 | 
					ActsAsTenant.with_tenant(wedding) do
 | 
				
			||||||
  Expense.create!(name: 'Photographer', amount: 3000, pricing_type: 'fixed')
 | 
					  [
 | 
				
			||||||
  Expense.create!(name: 'Country house', amount: 6000, pricing_type: 'fixed')
 | 
					    { name: 'Photographer', amount: 3000, pricing_type: 'fixed' },
 | 
				
			||||||
  Expense.create!(name: 'Catering', amount: 200, pricing_type: 'per_person')
 | 
					    { name: 'Country house', amount: 6000, pricing_type: 'fixed' },
 | 
				
			||||||
  Expense.create!(name: 'Flowers', amount: 500, pricing_type: 'fixed')
 | 
					    { name: 'Catering', amount: 200, pricing_type: 'per_person' },
 | 
				
			||||||
  Expense.create!(name: 'Band', amount: 1000, pricing_type: 'fixed')
 | 
					    { name: 'Flowers', amount: 500, pricing_type: 'fixed' },
 | 
				
			||||||
  Expense.create!(name: 'Wedding planner', amount: 2000, pricing_type: 'fixed')
 | 
					    { name: 'Band', amount: 1000, pricing_type: 'fixed' },
 | 
				
			||||||
  Expense.create!(name: 'Dress', amount: 1000, pricing_type: 'fixed')
 | 
					    { name: 'Wedding planner', amount: 2000, pricing_type: 'fixed' },
 | 
				
			||||||
  Expense.create!(name: 'Suit', amount: 500, pricing_type: 'fixed')
 | 
					    { name: 'Dress', amount: 1000, pricing_type: 'fixed' },
 | 
				
			||||||
  Expense.create!(name: 'Rings', amount: 1000, pricing_type: 'fixed')
 | 
					    { name: 'Suit', amount: 500, pricing_type: 'fixed' },
 | 
				
			||||||
  Expense.create!(name: 'Makeup', amount: 200, pricing_type: 'fixed')
 | 
					    { name: 'Rings', amount: 1000, pricing_type: 'fixed' },
 | 
				
			||||||
  Expense.create!(name: 'Hair', amount: 200, pricing_type: 'fixed')
 | 
					    { name: 'Makeup', amount: 200, pricing_type: 'fixed' },
 | 
				
			||||||
  Expense.create!(name: 'Transportation', amount: 3000, pricing_type: 'fixed')
 | 
					    { name: 'Hair', amount: 200, pricing_type: 'fixed' },
 | 
				
			||||||
  Expense.create!(name: 'Invitations', amount: 200, pricing_type: 'fixed')
 | 
					    { name: 'Transportation', amount: 3000, pricing_type: 'fixed' },
 | 
				
			||||||
  Expense.create!(name: 'Cake', amount: 500, pricing_type: 'fixed')
 | 
					    { name: 'Invitations', amount: 200, pricing_type: 'fixed' },
 | 
				
			||||||
 | 
					    { name: 'Cake', amount: 500, pricing_type: 'fixed' }
 | 
				
			||||||
 | 
					  ].then { Expense.insert_all!(it) }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Group.create!(name: "Jim's guests", icon: 'pi pi-heart').tap do |parent|
 | 
					  Group.create!(name: "Jim's guests", icon: 'pi pi-heart').tap do |parent|
 | 
				
			||||||
    parent.children.create!(name: "Jim's family", icon: 'pi pi-users').tap do |family|
 | 
					    parent.children.create!(name: "Jim's family", icon: 'pi pi-users').tap do |family|
 | 
				
			||||||
@ -56,19 +60,21 @@ ActsAsTenant.with_tenant(wedding) do
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  groups = Group.all
 | 
					  groups = Group.all
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  NUMBER_OF_GUESTS.times do
 | 
					  invitations = ([{}] * (NUMBER_OF_GUESTS * 0.8)).then { Invitation.insert_all!(it) }.rows.flatten
 | 
				
			||||||
    Guest.create!(
 | 
					
 | 
				
			||||||
 | 
					  NUMBER_OF_GUESTS.times.map do |i|
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
      name: Faker::Name.name,
 | 
					      name: Faker::Name.name,
 | 
				
			||||||
      phone: Faker::PhoneNumber.cell_phone,
 | 
					      phone: Faker::PhoneNumber.cell_phone,
 | 
				
			||||||
      group: groups.sample,
 | 
					      group_id: groups.sample.id,
 | 
				
			||||||
      status: Guest.statuses.keys.sample,
 | 
					      status: Guest.statuses.keys.sample,
 | 
				
			||||||
      invitation: (Invitation.create!(wedding:) if rand > 0.1),
 | 
					      invitation_id: invitations[i]
 | 
				
			||||||
    )
 | 
					    }
 | 
				
			||||||
  end
 | 
					  end.then { Guest.insert_all!(it) }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ActiveJob.perform_all_later(3.times.map { TableSimulatorJob.new(wedding.id) })
 | 
					  ActiveJob.perform_all_later(3.times.map { TableSimulatorJob.new(wedding.id) })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  'red'.paint.palette.triad(as: :hex).zip(Group.roots).each { |(color, group)| group.update!(color: color.paint.desaturate(40)) }
 | 
					  "red".dup.paint.palette.triad(as: :hex).zip(Group.roots).each { |(color, group)| group.update!(color: color.paint.desaturate(40)) }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Group.roots.each(&:colorize_children)
 | 
					  Group.roots.each(&:colorize_children)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -76,6 +82,6 @@ ActsAsTenant.with_tenant(wedding) do
 | 
				
			|||||||
    email: 'development@example.com',
 | 
					    email: 'development@example.com',
 | 
				
			||||||
    confirmed_at: Time.zone.now,
 | 
					    confirmed_at: Time.zone.now,
 | 
				
			||||||
    password: 'supersecretpassword',
 | 
					    password: 'supersecretpassword',
 | 
				
			||||||
    password_confirmation: 'supersecretpassword',
 | 
					    password_confirmation: 'supersecretpassword'
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user