summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2017-07-17 18:11:07 +0200
committerBob Van Landuyt <bob@vanlanduyt.co>2017-07-18 16:23:38 +0200
commit6f26f6f79f33fdb7e4e556b7f6b37999b78cd323 (patch)
tree53bd301927604facd1d0c13608cf84f9b47d517a
parent6a10626f981e1c4cd76e5d18e78880deba1b7fe3 (diff)
downloadgitlab-ce-bvl-free-system-namespace.tar.gz
Allow groups with the name systembvl-free-system-namespace
-rw-r--r--lib/gitlab/background_migration/migrate_system_uploads_to_new_folder.rb37
-rw-r--r--lib/gitlab/path_regex.rb1
-rw-r--r--spec/models/namespace_spec.rb2
3 files changed, 9 insertions, 31 deletions
diff --git a/lib/gitlab/background_migration/migrate_system_uploads_to_new_folder.rb b/lib/gitlab/background_migration/migrate_system_uploads_to_new_folder.rb
index 601c874bc9b..0881244ed49 100644
--- a/lib/gitlab/background_migration/migrate_system_uploads_to_new_folder.rb
+++ b/lib/gitlab/background_migration/migrate_system_uploads_to_new_folder.rb
@@ -4,44 +4,23 @@ module Gitlab
include Gitlab::Database::MigrationHelpers
attr_reader :old_folder, :new_folder
- def perform(old_folder, new_folder)
- @old_folder = old_folder
- @new_folder = new_folder
+ class Upload < ActiveRecord::Base
+ self.table_name = 'uploads'
+ include EachBatch
+ end
+ def perform(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
- 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
diff --git a/lib/gitlab/path_regex.rb b/lib/gitlab/path_regex.rb
index d81f825ef96..60a32d5d5ea 100644
--- a/lib/gitlab/path_regex.rb
+++ b/lib/gitlab/path_regex.rb
@@ -49,7 +49,6 @@ module Gitlab
sent_notifications
services
snippets
- system
teams
u
unicorn_test
diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb
index 89ea5ceda95..a4090b37f65 100644
--- a/spec/models/namespace_spec.rb
+++ b/spec/models/namespace_spec.rb
@@ -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