From b1b50304d467054efde4e631ae46c93d66237470 Mon Sep 17 00:00:00 2001 From: ChrisBAshton Date: Wed, 26 Feb 2025 10:35:53 +0000 Subject: [PATCH 1/3] Fix timestamp for old data migration We want data migrations to appear in the order they were defined. This particular migration was short of one number, which placed it before `2024121711524600_convert_text_columns_to_utf8mb4.rb` in the list. --- ...5012315210000_retroactively_accept_consultation_principles.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename db/data_migration/{202501231521000_retroactively_accept_consultation_principles.rb => 2025012315210000_retroactively_accept_consultation_principles.rb} (100%) diff --git a/db/data_migration/202501231521000_retroactively_accept_consultation_principles.rb b/db/data_migration/2025012315210000_retroactively_accept_consultation_principles.rb similarity index 100% rename from db/data_migration/202501231521000_retroactively_accept_consultation_principles.rb rename to db/data_migration/2025012315210000_retroactively_accept_consultation_principles.rb From d201efa9970110d5b35c35159d20ef11d3e54ebb Mon Sep 17 00:00:00 2001 From: ChrisBAshton Date: Wed, 26 Feb 2025 10:54:06 +0000 Subject: [PATCH 2/3] Simplify link check report association with editions The polymorphic association was added in November 2017 with no explanation: https://github.com/alphagov/whitehall/pull/3557/commits/03c47344a42243f96990559e33125f73edc4d00b Since then, there doesn't seem to have been a single link check report which is associated with anything other than an Edition: ``` $ LinkCheckerApiReport.distinct.pluck(:link_reportable_type) => ["Edition"] ``` Therefore let's remove the obtuse reference and make it clear that a link check report is associated with an edition (not a 'linkable'). This should also cut down on quite a lot of DB space, since we're currently storing the word "Edition" on every single link check report (almost 12 million rows in the DB). We'll deploy this and run the migration, before removing the old fields. --- ...dd_edition_id_to_link_checker_api_reports.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 db/migrate/20250226105201_add_edition_id_to_link_checker_api_reports.rb diff --git a/db/migrate/20250226105201_add_edition_id_to_link_checker_api_reports.rb b/db/migrate/20250226105201_add_edition_id_to_link_checker_api_reports.rb new file mode 100644 index 00000000000..313645ab612 --- /dev/null +++ b/db/migrate/20250226105201_add_edition_id_to_link_checker_api_reports.rb @@ -0,0 +1,17 @@ +class AddEditionIdToLinkCheckerApiReports < ActiveRecord::Migration[8.0] + def up + # Add the new column + add_reference :link_checker_api_reports, :edition, foreign_key: true + + # Migrate data from polymorphic association to edition_id + execute <<-SQL.squish + UPDATE link_checker_api_reports + SET edition_id = link_reportable_id + WHERE link_reportable_type = 'Edition' + SQL + end + + def down + remove_reference :link_checker_api_reports, :edition, foreign_key: true + end +end From 6cf63dc600ec86ee1aa9d6bb88bd9fac64cb8168 Mon Sep 17 00:00:00 2001 From: ChrisBAshton Date: Wed, 26 Feb 2025 15:05:25 +0000 Subject: [PATCH 3/3] Add `db:migrate` step to CI Adding a DB migration fails CI without this. See https://github.com/alphagov/whitehall/actions/runs/13546825047/job/37860430804?pr=9986 --- .github/workflows/minitest.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/minitest.yml b/.github/workflows/minitest.yml index d7e1c834e34..72a348a466b 100644 --- a/.github/workflows/minitest.yml +++ b/.github/workflows/minitest.yml @@ -59,7 +59,9 @@ jobs: env: RAILS_ENV: test TEST_DATABASE_URL: ${{ steps.setup-mysql.outputs.db-url }} - run: bundle exec rails db:setup + run: | + bundle exec rails db:setup + bundle exec rails db:migrate - name: Run Minitest env: