1
0

20120919063304_add_username_to_users.rb 428 B

12345678910111213141516171819
  1. class AddUsernameToUsers < ActiveRecord::Migration[4.2]
  2. class User < ActiveRecord::Base
  3. end
  4. def up
  5. add_column :users, :username, :string
  6. User.find_each do |user|
  7. user.update_attribute :username, user.email.gsub(/@.*$/, '')
  8. end
  9. change_column :users, :username, :string, :null => false
  10. add_index :users, :username, :unique => true
  11. end
  12. def down
  13. remove_column :users, :username
  14. end
  15. end