From f8e8858717a3b0a136624c0691c59900bccb539a Mon Sep 17 00:00:00 2001 From: ChrisBAshton Date: Wed, 26 Feb 2025 15:19:01 +0000 Subject: [PATCH] fixup --- ...025022610370000_remove_old_link_checker_reports.rb | 11 +++++++++++ ...reportable_fields_from_link_checker_api_reports.rb | 2 ++ 2 files changed, 13 insertions(+) create mode 100644 db/data_migration/2025022610370000_remove_old_link_checker_reports.rb diff --git a/db/data_migration/2025022610370000_remove_old_link_checker_reports.rb b/db/data_migration/2025022610370000_remove_old_link_checker_reports.rb new file mode 100644 index 00000000000..bce1e88a41c --- /dev/null +++ b/db/data_migration/2025022610370000_remove_old_link_checker_reports.rb @@ -0,0 +1,11 @@ +# To address https://github.com/alphagov/whitehall/issues/6011, we need +# to remove old link checker reports and switch to a 'has_one' relationship. + +Edition.find_each do |edition| + reports = edition.link_check_reports.order(created_at: :desc).to_a + next if reports.size <= 1 + + # Keep the most recent report and delete the rest + reports_to_delete = reports.drop(1) + reports_to_delete.each(&:destroy) +end diff --git a/db/migrate/20250226115201_remove_link_reportable_fields_from_link_checker_api_reports.rb b/db/migrate/20250226115201_remove_link_reportable_fields_from_link_checker_api_reports.rb index 8dd79e84697..ff726efb866 100644 --- a/db/migrate/20250226115201_remove_link_reportable_fields_from_link_checker_api_reports.rb +++ b/db/migrate/20250226115201_remove_link_reportable_fields_from_link_checker_api_reports.rb @@ -1,3 +1,4 @@ +# rubocop:disable Rails/BulkChangeTable class RemoveLinkReportableFieldsFromLinkCheckerApiReports < ActiveRecord::Migration[8.0] def up # Catch any link reports that have been created since @@ -26,3 +27,4 @@ def down SQL end end +# rubocop:enable Rails/BulkChangeTable