Sha256: cdc8bb8489627496a064c443ef8e923afc911c3631e69bc087ec0d9730a889d7

Contents?: true

Size: 391 Bytes

Versions: 2

Compression:

Stored size: 391 Bytes

Contents

class AddUsernameToUser < ActiveRecord::Migration[6.0]
  def change
    add_column :users, :username, :string
    add_index :users, :username

    puts "Computing username for existing emails"
    User.reset_column_information
    User.all.each do |u|
      puts "User: #{u.email} into #{u.email.split("@").first}"
      u.username = u.email.split("@").first
      u.save!
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
thecore_ui_commons-2.1.8 db/migrate/20200515070620_add_username_to_user.rb
thecore_ui_commons-2.1.7 db/migrate/20200515070620_add_username_to_user.rb