rosa-build/db/migrate/20111021164945_delete_nickn...

14 lines
491 B
Ruby
Raw Permalink Normal View History

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_]/, '_'))}
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_]/, '_'))}
end
end