Skip to content

Commit

Permalink
Remove unused 'link_reportable_type' / 'link_reportable_id' fields
Browse files Browse the repository at this point in the history
Following on from #9986 which introduces the 'edition_id' field,
we no longer need the old polymorphic fields.
  • Loading branch information
ChrisBAshton committed Feb 26, 2025
1 parent d201efa commit 136258c
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class RemoveLinkReportableFieldsFromLinkCheckerApiReports < ActiveRecord::Migration[8.0]
def up
# Catch any link reports that have been created since
# `AddEditionIdToLinkCheckerApiReports` was run.
execute <<-SQL.squish
UPDATE link_checker_api_reports
SET edition_id = link_reportable_id
WHERE link_reportable_type = 'Edition' AND edition_id IS NULL
SQL

remove_index :link_checker_api_reports, name: "index_link_checker_api_reportable"
remove_column :link_checker_api_reports, :link_reportable_type
remove_column :link_checker_api_reports, :link_reportable_id
end

def down
add_column :link_checker_api_reports, :link_reportable_type, :string
add_column :link_checker_api_reports, :link_reportable_id, :integer
add_index :link_checker_api_reports, [:link_reportable_type, :link_reportable_id], name: "index_link_checker_api_reportable"

# Restore data
execute <<-SQL.squish
UPDATE link_checker_api_reports
SET link_reportable_type = 'Edition', link_reportable_id = edition_id
WHERE edition_id IS NOT NULL
SQL
end
end

0 comments on commit 136258c

Please sign in to comment.