Init username migration and rake task for create appropriate namespace
This commit is contained in:
parent
26622f4c8f
commit
5ca1772385
2 changed files with 18 additions and 0 deletions
5
db/migrate/20121123104937_add_username_to_user.rb
Normal file
5
db/migrate/20121123104937_add_username_to_user.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class AddUsernameToUser < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :users, :username, :string, null: true
|
||||||
|
end
|
||||||
|
end
|
13
lib/tasks/gitlab/activate_namespaces.rake
Normal file
13
lib/tasks/gitlab/activate_namespaces.rake
Normal 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
|
Loading…
Reference in a new issue