Init username migration and rake task for create appropriate namespace

Dmitriy Zaporozhets 2012-11-23 06:34:09 +03:00
parent 26622f4c8f
commit 5ca1772385
2 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,5 @@
class AddUsernameToUser < ActiveRecord::Migration
def change
add_column :users, :username, :string, null: true
end
end

View File

@ -0,0 +1,13 @@
namespace :gitlab do
desc "GITLAB | Enable usernames and namespaces for user projects"
task activate_namespaces: :environment do
User.find_each(batch_size: 500) do |user|
User.transaction do
username = user.email.match(/^[^@]*/)[0]
user.update_attributes!(username: username)
user.create_namespace!(code: username, name: user.name)
print '.'.green
end
end
end
end