Emi Matchu
413d2eed91
Oh right, this should only run in the up direction! And also we can get a lot faster by preloading the translations.
20 lines
568 B
Ruby
20 lines
568 B
Ruby
class AddNameToSpeciesAndColor < ActiveRecord::Migration[7.1]
|
|
def change
|
|
add_column :species, :name, :string, null: false
|
|
add_column :colors, :name, :string, null: false
|
|
|
|
reversible do |direction|
|
|
direction.up do
|
|
Species.includes(:translations).find_each do |species|
|
|
species.name = species.translation_for(:en).name
|
|
species.save!
|
|
end
|
|
|
|
Color.includes(:translations).find_each do |color|
|
|
color.name = color.translation_for(:en).name
|
|
color.save!
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|