Browse Source

rake task to create rent period associations for orgs that have none (#2443)

pull/2446/head
Arthur Campbell 8 months ago committed by GitHub
parent
commit
461b46bc4a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 11
      lib/tasks/create_organisation_rent_periods.rake

11
lib/tasks/create_organisation_rent_periods.rake

@ -0,0 +1,11 @@
desc "Create OrganisationRentPeriods for organisations that have none as they were previously assumed to have all"
task create_organisation_rent_periods: :environment do
org_ids_with_no_associated_rent_periods = Organisation.includes(:organisation_rent_periods).group(:id).count(:organisation_rent_periods).select { |_org_id, period_count| period_count.zero? }.keys
org_ids_with_no_associated_rent_periods.each do |organisation_id|
OrganisationRentPeriod.transaction do
(1..11).each do |rent_period|
OrganisationRentPeriod.create(organisation_id:, rent_period:)
end
end
end
end
Loading…
Cancel
Save