diff options
author | Felipe Artur <felipefac@gmail.com> | 2019-03-27 21:19:12 +0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2019-03-27 21:19:12 +0300 |
commit | 16a3fea3998e813b95d7d09ea31f6a88dc908102 (patch) | |
tree | f896b456433d21ab5d8b3dd24625348175ac06a6 /lib/gitlab/background_migration | |
parent | 294c5c41beaac1fbc60c67df2c8745f7583544a1 (diff) | |
parent | 97f8d4e96870324c4ce6534022397d33c4bf5dbc (diff) |
Merge master
Diffstat (limited to 'lib/gitlab/background_migration')
7 files changed, 55 insertions, 23 deletions
diff --git a/lib/gitlab/background_migration/archive_legacy_traces.rb b/lib/gitlab/background_migration/archive_legacy_traces.rb index 92096e29ef1..7ee783b8489 100644 --- a/lib/gitlab/background_migration/archive_legacy_traces.rb +++ b/lib/gitlab/background_migration/archive_legacy_traces.rb @@ -11,11 +11,10 @@ module Gitlab # So we chose a way to use ::Ci::Build directly and we don't change the `archive!` method until 11.1 ::Ci::Build.finished.without_archived_trace .where(id: start_id..stop_id).find_each do |build| - begin - build.trace.archive! - rescue => e - Rails.logger.error "Failed to archive live trace. id: #{build.id} message: #{e.message}" - end + + build.trace.archive! + rescue => e + Rails.logger.error "Failed to archive live trace. id: #{build.id} message: #{e.message}" end end end diff --git a/lib/gitlab/background_migration/encrypt_columns.rb b/lib/gitlab/background_migration/encrypt_columns.rb index b9ad8267e37..173543b7c25 100644 --- a/lib/gitlab/background_migration/encrypt_columns.rb +++ b/lib/gitlab/background_migration/encrypt_columns.rb @@ -91,7 +91,8 @@ module Gitlab # No need to do anything if the plaintext is nil, or an encrypted # value already exists - return nil unless plaintext.present? && !ciphertext.present? + return unless plaintext.present? + return if ciphertext.present? # attr_encrypted will calculate and set the expected value for us instance.public_send("#{plain_column}=", plaintext) # rubocop:disable GitlabSecurity/PublicSend diff --git a/lib/gitlab/background_migration/migrate_events_to_push_event_payloads.rb b/lib/gitlab/background_migration/migrate_events_to_push_event_payloads.rb index 38fecac1bfe..42fcaa87e66 100644 --- a/lib/gitlab/background_migration/migrate_events_to_push_event_payloads.rb +++ b/lib/gitlab/background_migration/migrate_events_to_push_event_payloads.rb @@ -24,7 +24,7 @@ module Gitlab def commit_title commit = commits.last - return nil unless commit && commit[:message] + return unless commit && commit[:message] index = commit[:message].index("\n") message = index ? commit[:message][0..index] : commit[:message] diff --git a/lib/gitlab/background_migration/normalize_ldap_extern_uids_range.rb b/lib/gitlab/background_migration/normalize_ldap_extern_uids_range.rb index 698f5e46c0c..48aa369705f 100644 --- a/lib/gitlab/background_migration/normalize_ldap_extern_uids_range.rb +++ b/lib/gitlab/background_migration/normalize_ldap_extern_uids_range.rb @@ -302,14 +302,12 @@ module Gitlab ldap_identities = Identity.where("provider like 'ldap%'").where(id: start_id..end_id) ldap_identities.each do |identity| - begin - identity.extern_uid = Gitlab::Auth::LDAP::DN.new(identity.extern_uid).to_normalized_s - unless identity.save - Rails.logger.info "Unable to normalize \"#{identity.extern_uid}\". Skipping." - end - rescue Gitlab::Auth::LDAP::DN::FormatError => e - Rails.logger.info "Unable to normalize \"#{identity.extern_uid}\" due to \"#{e.message}\". Skipping." + identity.extern_uid = Gitlab::Auth::LDAP::DN.new(identity.extern_uid).to_normalized_s + unless identity.save + Rails.logger.info "Unable to normalize \"#{identity.extern_uid}\". Skipping." end + rescue Gitlab::Auth::LDAP::DN::FormatError => e + Rails.logger.info "Unable to normalize \"#{identity.extern_uid}\" due to \"#{e.message}\". Skipping." end end diff --git a/lib/gitlab/background_migration/populate_merge_request_assignees_table.rb b/lib/gitlab/background_migration/populate_merge_request_assignees_table.rb new file mode 100644 index 00000000000..a4c6540c61b --- /dev/null +++ b/lib/gitlab/background_migration/populate_merge_request_assignees_table.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module Gitlab + module BackgroundMigration + # This background migration creates records on merge_request_assignees according + # to the given merge request IDs range. A _single_ INSERT is issued for the given range. + # This is required for supporting multiple assignees on merge requests. + class PopulateMergeRequestAssigneesTable + def perform(from_id, to_id) + select_sql = + MergeRequest + .where(merge_request_assignees_not_exists_clause) + .where(id: from_id..to_id) + .where('assignee_id IS NOT NULL') + .select(:id, :assignee_id) + .to_sql + + execute("INSERT INTO merge_request_assignees (merge_request_id, user_id) #{select_sql}") + end + + private + + def merge_request_assignees_not_exists_clause + <<~SQL + NOT EXISTS (SELECT 1 FROM merge_request_assignees + WHERE merge_request_assignees.merge_request_id = merge_requests.id) + SQL + end + + def execute(sql) + @connection ||= ActiveRecord::Base.connection + @connection.execute(sql) + end + end + end +end diff --git a/lib/gitlab/background_migration/populate_untracked_uploads.rb b/lib/gitlab/background_migration/populate_untracked_uploads.rb index a19dc9747fb..755b5ee725a 100644 --- a/lib/gitlab/background_migration/populate_untracked_uploads.rb +++ b/lib/gitlab/background_migration/populate_untracked_uploads.rb @@ -34,18 +34,16 @@ module Gitlab def filter_error_files(files) files.partition do |file| - begin - file.to_h - true - rescue => e - msg = <<~MSG + file.to_h + true + rescue => e + msg = <<~MSG Error parsing path "#{file.path}": #{e.message} #{e.backtrace.join("\n ")} MSG - Rails.logger.error(msg) - false - end + Rails.logger.error(msg) + false end end diff --git a/lib/gitlab/background_migration/populate_untracked_uploads_dependencies.rb b/lib/gitlab/background_migration/populate_untracked_uploads_dependencies.rb index 4a9a62aaeb5..a84f794bfae 100644 --- a/lib/gitlab/background_migration/populate_untracked_uploads_dependencies.rb +++ b/lib/gitlab/background_migration/populate_untracked_uploads_dependencies.rb @@ -127,7 +127,7 @@ module Gitlab full_path = matchd[1] project = Gitlab::BackgroundMigration::PopulateUntrackedUploadsDependencies::Project.find_by_full_path(full_path) - return nil unless project + return unless project project.id end |