forked from OpenNeo/impress
Improve species/color name migration performance & correctness
Oh right, this should only run in the up direction! And also we can get a lot faster by preloading the translations.
This commit is contained in:
parent
ce64f12cc3
commit
413d2eed91
1 changed files with 11 additions and 7 deletions
|
@ -3,14 +3,18 @@ class AddNameToSpeciesAndColor < ActiveRecord::Migration[7.1]
|
||||||
add_column :species, :name, :string, null: false
|
add_column :species, :name, :string, null: false
|
||||||
add_column :colors, :name, :string, null: false
|
add_column :colors, :name, :string, null: false
|
||||||
|
|
||||||
Species.find_each do |species|
|
reversible do |direction|
|
||||||
|
direction.up do
|
||||||
|
Species.includes(:translations).find_each do |species|
|
||||||
species.name = species.translation_for(:en).name
|
species.name = species.translation_for(:en).name
|
||||||
species.save!
|
species.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
Color.find_each do |color|
|
Color.includes(:translations).find_each do |color|
|
||||||
color.name = color.translation_for(:en).name
|
color.name = color.translation_for(:en).name
|
||||||
color.save!
|
color.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue