From b0faa81afe5cf2c6062dfbd130b40e9d1a2dec90 Mon Sep 17 00:00:00 2001 From: samyou-softwire Date: Wed, 8 Apr 2026 09:34:32 +0100 Subject: [PATCH] CLDC-4313: Remove redundant queries from rake --- ...rrect_value_and_mortgage_for_2025_sales_logs.rake | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 lib/tasks/correct_value_and_mortgage_for_2025_sales_logs.rake diff --git a/lib/tasks/correct_value_and_mortgage_for_2025_sales_logs.rake b/lib/tasks/correct_value_and_mortgage_for_2025_sales_logs.rake new file mode 100644 index 000000000..5199ea8ef --- /dev/null +++ b/lib/tasks/correct_value_and_mortgage_for_2025_sales_logs.rake @@ -0,0 +1,12 @@ +desc "Clears mortgage and purchase price (the 'value' field) values for sales logs in the database if they are over 999,999" +task correct_value_and_mortgage_for_2025_sales_logs: :environment do + mortgage_incorrect_logs = SalesLog.filter_by_year_or_later(2025).where("mortgage > 999999") + value_incorrect_logs = SalesLog.filter_by_year_or_later(2025).where("value > 999999") + all_incorrect_logs = (mortgage_incorrect_logs + value_incorrect_logs).uniq + puts "Correcting #{all_incorrect_logs.count} sales logs, #{all_incorrect_logs.map(&:id)}" + + mortgage_incorrect_logs.update!(mortgage: nil) + value_incorrect_logs.update!(value: nil) + + puts "Done" +end