diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-07-17 18:11:07 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-07-18 16:23:38 +0200 |
commit | 6f26f6f79f33fdb7e4e556b7f6b37999b78cd323 (patch) | |
tree | 53bd301927604facd1d0c13608cf84f9b47d517a /lib | |
parent | 6a10626f981e1c4cd76e5d18e78880deba1b7fe3 (diff) | |
download | gitlab-ce-6f26f6f79f33fdb7e4e556b7f6b37999b78cd323.tar.gz |
Allow groups with the name systembvl-free-system-namespace
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/background_migration/migrate_system_uploads_to_new_folder.rb | 37 | ||||
-rw-r--r-- | lib/gitlab/path_regex.rb | 1 |
2 files changed, 8 insertions, 30 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 |