29 lines
576 B
Ruby
29 lines
576 B
Ruby
|
class MigrateSteps < ActiveRecord::Migration[5.0]
|
||
|
|
||
|
class RecipeStub < ActiveRecord::Base
|
||
|
self.table_name = 'recipes'
|
||
|
end
|
||
|
|
||
|
class RecipeStepStub < ActiveRecord::Base
|
||
|
self.table_name = 'recipe_steps'
|
||
|
end
|
||
|
|
||
|
def up
|
||
|
RecipeStub.all.each do |r|
|
||
|
text = ''
|
||
|
RecipeStepStub.where(recipe_id: r.id).order(:sort_order).each do |s|
|
||
|
text << '1. '
|
||
|
text << s.step
|
||
|
text << "\n"
|
||
|
end
|
||
|
|
||
|
r.step_text = text
|
||
|
r.save!
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def down
|
||
|
raise ActiveRecord::IrreversibleMigration, "Can't undo step migration"
|
||
|
end
|
||
|
end
|