-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove unused 'link_reportable_type' / 'link_reportable_id' fields
Following on from #9986 which introduces the 'edition_id' field, we no longer need the old polymorphic fields.
- Loading branch information
1 parent
d201efa
commit 136258c
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
db/migrate/20250226115201_remove_link_reportable_fields_from_link_checker_api_reports.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |