Allow groups with the name system

This commit is contained in:
Bob Van Landuyt 2017-07-17 18:11:07 +02:00
parent 6a10626f98
commit 6f26f6f79f
3 changed files with 9 additions and 31 deletions

View file

@ -4,44 +4,23 @@ module Gitlab
include Gitlab::Database::MigrationHelpers
attr_reader :old_folder, :new_folder
class Upload < ActiveRecord::Base
self.table_name = 'uploads'
include EachBatch
end
def perform(old_folder, new_folder)
@old_folder = old_folder
@new_folder = new_folder
replace_sql = replace_sql(uploads[:path], old_folder, new_folder)
affected_uploads = Upload.where(uploads[:path].matches("#{old_folder}%"))
while remaining_rows > 0
sql = "UPDATE uploads "\
"SET path = #{replace_sql} "\
"WHERE uploads.id IN "\
" (SELECT uploads.id FROM uploads "\
" WHERE #{affected_uploads.to_sql} LIMIT 1000)"
connection.execute(sql)
affected_uploads.each_batch do |batch|
batch.update_all("path = #{replace_sql}")
end
end
def uploads
Arel::Table.new('uploads')
end
def remaining_rows
remaining_result = connection.exec_query("SELECT count(id) FROM uploads WHERE #{affected_uploads.to_sql}")
remaining = remaining_result.first['count'].to_i
logger.info "#{remaining} uploads remaining"
remaining
end
def affected_uploads
uploads[:path].matches("#{old_folder}%")
end
def connection
ActiveRecord::Base.connection
end
def logger
Sidekiq.logger || Rails.logger || Logger.new(STDOUT)
end
end
end
end

View file

@ -49,7 +49,6 @@ module Gitlab
sent_notifications
services
snippets
system
teams
u
unicorn_test

View file

@ -44,7 +44,7 @@ describe Namespace, models: true do
end
context "is case insensitive" do
let(:group) { build(:group, path: "System") }
let(:group) { build(:group, path: "Groups") }
it { expect(group).not_to be_valid }
end