Merge branch 'szzh' of http://repository.trustie.net/xianbo/trustie2 into szzh
commit
42b3fd9584
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,6 @@
|
||||
class AddColumnToHomeworkattaches < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :homework_attaches, :score, :float, default: 0
|
||||
add_column :homework_attaches, :is_teacher_score, :integer, :default => 0
|
||||
end
|
||||
end
|
@ -0,0 +1,18 @@
|
||||
class UpdateScoreToHomeworkattaches < ActiveRecord::Migration
|
||||
def up
|
||||
sql = ("UPDATE homework_attaches set is_teacher_score = 1,
|
||||
score = (SELECT AVG(seems_rateable_rates.stars) FROM seems_rateable_rates
|
||||
WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id
|
||||
AND is_teacher_score = 1 GROUP BY rateable_id);")
|
||||
sql_student = ("UPDATE homework_attaches set is_teacher_score = 0,
|
||||
score = (SELECT AVG(seems_rateable_rates.stars) FROM seems_rateable_rates
|
||||
WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id
|
||||
AND is_teacher_score = 0 GROUP BY rateable_id) WHERE homework_attaches.score = 0 OR homework_attaches.score is NULL
|
||||
")
|
||||
execute(sql)
|
||||
execute(sql_student)
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
Loading…
Reference in new issue