From 8084968c45e0c2e5d59f8c6d6f226fac06934b68 Mon Sep 17 00:00:00 2001 From: Arthur Campbell Date: Thu, 2 May 2024 18:13:54 +0100 Subject: [PATCH] rake task to create rent period associations for orgs that have none --- lib/tasks/create_organisation_rent_periods.rake | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 lib/tasks/create_organisation_rent_periods.rake diff --git a/lib/tasks/create_organisation_rent_periods.rake b/lib/tasks/create_organisation_rent_periods.rake new file mode 100644 index 000000000..002d24513 --- /dev/null +++ b/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