forked from OpenNeo/impress
Emi Matchu
a1066d9c8a
Like with Species, Color, and Zone, we're moving the translation data
directly onto the model, and just using English. This will simplify
some of our queries a lot (way fewer joins!), and it's what Neopets
does now anyway, and I have a secret hope that removing the complexity
along the codepath for `item.name` might help speed up large item lists
if we're lucky?? 🤞
Anyway, this is the first step, performing the migration to copy the
data onto the `items` table, making sure to keep them in sync for the
2020 app for now!
26 lines
906 B
Ruby
26 lines
906 B
Ruby
class AddTranslatedFieldsDirectlyToItems < ActiveRecord::Migration[7.1]
|
|
def change
|
|
add_column :items, :name, :string, null: false
|
|
add_column :items, :description, :text, null: false, default: ""
|
|
add_column :items, :rarity, :string, null: false, default: ""
|
|
|
|
reversible do |direction|
|
|
direction.up do
|
|
total_count = Item.count
|
|
saved_count = 0
|
|
Item.includes(:translations).find_in_batches do |items|
|
|
Item.transaction do
|
|
items.each do |item|
|
|
item.name = item.translation_for(:en).name
|
|
item.description = item.translation_for(:en).description || ""
|
|
item.rarity = item.translation_for(:en).rarity || ""
|
|
item.save!
|
|
end
|
|
saved_count += items.size
|
|
puts "Saved #{saved_count} of #{total_count} items"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|