2011-10-21 18:17:49 +01:00
|
|
|
class DeleteNicknameInitUname < ActiveRecord::Migration
|
|
|
|
def self.up
|
|
|
|
remove_column :users, :nickname
|
2014-01-21 04:51:49 +00:00
|
|
|
add_index :users, :uname, unique: true
|
|
|
|
User.all.each {|u| User.where(id: u.id).update_all(uname: u.email.split('@').first.gsub(/[^a-zA-Z0-9_]/, '_'))}
|
2011-10-21 18:17:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.down
|
|
|
|
add_column :users, :nickname, :string
|
|
|
|
remove_index :users, :uname
|
2014-01-21 04:51:49 +00:00
|
|
|
User.all.each {|u| User.where(id: u.id).update_all(nickname: u.email.split('@').first.gsub(/[^a-zA-Z0-9_]/, '_'))}
|
2011-10-21 18:17:49 +01:00
|
|
|
end
|
|
|
|
end
|