Commit 6f26f6f7 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Allow groups with the name system

parent 6a10626f
...@@ -4,44 +4,23 @@ module Gitlab ...@@ -4,44 +4,23 @@ module Gitlab
include Gitlab::Database::MigrationHelpers include Gitlab::Database::MigrationHelpers
attr_reader :old_folder, :new_folder attr_reader :old_folder, :new_folder
def perform(old_folder, new_folder) class Upload < ActiveRecord::Base
@old_folder = old_folder self.table_name = 'uploads'
@new_folder = new_folder include EachBatch
end
def perform(old_folder, new_folder)
replace_sql = replace_sql(uploads[:path], old_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 affected_uploads.each_batch do |batch|
sql = "UPDATE uploads "\ batch.update_all("path = #{replace_sql}")
"SET path = #{replace_sql} "\
"WHERE uploads.id IN "\
" (SELECT uploads.id FROM uploads "\
" WHERE #{affected_uploads.to_sql} LIMIT 1000)"
connection.execute(sql)
end end
end end
def uploads def uploads
Arel::Table.new('uploads') Arel::Table.new('uploads')
end 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 end
end end
...@@ -49,7 +49,6 @@ module Gitlab ...@@ -49,7 +49,6 @@ module Gitlab
sent_notifications sent_notifications
services services
snippets snippets
system
teams teams
u u
unicorn_test unicorn_test
......
...@@ -44,7 +44,7 @@ describe Namespace, models: true do ...@@ -44,7 +44,7 @@ describe Namespace, models: true do
end end
context "is case insensitive" do context "is case insensitive" do
let(:group) { build(:group, path: "System") } let(:group) { build(:group, path: "Groups") }
it { expect(group).not_to be_valid } it { expect(group).not_to be_valid }
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment