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

15 lines
533 B
Ruby
Raw Normal View History

2012-01-30 20:39:34 +00:00
# -*- encoding : utf-8 -*-
class DeleteNicknameInitUname < ActiveRecord::Migration
def self.up
remove_column :users, :nickname
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
User.all.each {|u| User.where(:id => u.id).update_all(:nickname => u.email.split('@').first.gsub(/[^a-zA-Z0-9_]/, '_'))}
end
end