Skip to content

Commit 06de1d7

Browse files
committed
Add data migrator rake task for offsite links
Offsite links now support having many parents. Hence, the need to migrate data from the old table to the new join table. This rake task helps to action it out and takes care of some orphaned offsite links as well. There's an unlikely edge case that an existing offsite link will have no parent and not belong in a feature list. In such case, we simply skip and log it to the console, as there's not much that can be done to those.
1 parent ef6f439 commit 06de1d7

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copy legacy parent_id/parent_type on offsite_links into the new polymorphic offsite_link_parents join table
2+
# This is in line with the new design where offsite links can have multiple parents
3+
4+
scope = OffsiteLink.all
5+
total = scope.count
6+
processed = 0
7+
skipped = 0
8+
9+
scope.find_each do |offsite_link|
10+
OffsiteLinkParent.find_or_create_by!(
11+
offsite_link: offsite_link,
12+
parent_id: offsite_link.parent_id,
13+
parent_type: offsite_link.parent_type,
14+
)
15+
processed += 1
16+
end
17+
18+
puts "\nMigration complete: #{processed}/#{total} migrated, #{skipped} skipped"

0 commit comments

Comments
 (0)