class AddCourseidToEnabledModules < ActiveRecord::Migration def change add_column :enabled_modules, :course_id, :int EnabledModule.all.each do |enablemodule| project = Project.find_by_id(enablemodule.project_id) if project && project.project_type == 1 enablemodule.course_id = board.project_id enablemodule.save end end end end