2014-06-04 09:19:01 +08:00
|
|
|
class AddCourseidToToMembers < ActiveRecord::Migration
|
|
|
|
def change
|
|
|
|
add_column :members, :course_id, :int
|
2014-06-04 11:59:26 +08:00
|
|
|
change_column_null(:members, :project_id, true)
|
|
|
|
remove_index :members, name: 'index_members_on_user_id_and_project_id'
|
|
|
|
add_index "members", ["user_id", "project_id","course_id"], :name => "index_members_on_user_id_and_project_id", :unique => true
|
|
|
|
|
|
|
|
Member.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all("course_id = project_id")
|
|
|
|
Member.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all(project_id: -1)
|
2014-06-04 09:19:01 +08:00
|
|
|
|
|
|
|
# 课程成员数据迁移
|
2014-06-04 11:59:26 +08:00
|
|
|
#Member.all.each do |member|
|
|
|
|
# project = Project.find_by_id(member.project_id)
|
|
|
|
# if project && project.project_type == 1
|
|
|
|
# member.course_id = member.project_id
|
|
|
|
# member.project_id = -1
|
|
|
|
# member.save
|
|
|
|
# end
|
|
|
|
#end
|
2014-06-04 09:19:01 +08:00
|
|
|
end
|
|
|
|
end
|