osem-fcy/db/migrate/20141104131625_generate_username.rb
divyanshumehta cdf794ecbf Add Style/SelfAssignment Rubocop cop
The cop enforces use of self assignment operator E.g. a=a+2 gets
written as a+=2. Also the offenses listed in rubocop.todo.yml
have been corrected automatically with the --auto-correct option.
Fixes issue #1531
2017-06-14 09:22:19 +05:30

15 lines
395 B
Ruby

class GenerateUsername < ActiveRecord::Migration
class TempUser < ActiveRecord::Base
self.table_name = 'users'
end
def change
TempUser.all.each do |user|
if user.username.blank?
username = user.email.split('@')[0]
username += user.id.to_s if TempUser.find_by(username: username)
user.update_attributes(username: username)
end
end
end
end