2014-06-03 16:21:00 +08:00
|
|
|
class AddCourseidToEnabledModules < ActiveRecord::Migration
|
|
|
|
def change
|
|
|
|
add_column :enabled_modules, :course_id, :int
|
|
|
|
|
2014-06-18 11:08:44 +08:00
|
|
|
#couese_id不能直接设置为project_id
|
|
|
|
#EnabledModule.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all("course_id = project_id")
|
|
|
|
#EnabledModule.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all(project_id: -1)
|
2014-06-04 11:59:26 +08:00
|
|
|
|
2014-07-01 15:29:16 +08:00
|
|
|
|
2014-06-18 11:08:44 +08:00
|
|
|
EnabledModule.all.each do |enablemodule|
|
|
|
|
project = Project.find_by_id(enablemodule.project_id)
|
|
|
|
if project && project.project_type == 1
|
|
|
|
enablemodule.course_id = project.course_extra.id
|
|
|
|
enablemodule.project_id = -1
|
2014-07-01 15:29:16 +08:00
|
|
|
enablemodule.save(:validate => false)
|
2014-06-18 11:08:44 +08:00
|
|
|
end
|
|
|
|
end
|
2014-06-03 16:21:00 +08:00
|
|
|
end
|
|
|
|
end
|