积分初始数据迁移

This commit is contained in:
huang 2017-05-04 13:56:43 +08:00
parent 640dd285c1
commit eaed13dbc8
1 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,22 @@
class SyncGradeForUser < ActiveRecord::Migration
def change
count = User.all.count / 30 + 2
transaction do
for i in 1 ... count do i
User.page(i).per(30).each do |u|
if u.user_extensions
unless u.user_extensions.try(:school).nil?
Grade.create(:user_id => u.id, :container_id => u.id, :container_type => "Account", :score => 500)
end
end
if !u.mail.nil?
Grade.create(:user_id => u.id, :container_id => u.id, :container_type => "Mail", :score => 500)
end
if !u.phone.nil?
Grade.create(:user_id => u.id, :container_id => u.id, :container_type => "Phone", :score => 500)
end
end
end
end
end
end