Welcome to mirror list, hosted at ThFree Co, Russian Federation.

nullify_creator_id_column_of_orphaned_projects.rb « background_migration « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e1ea0c66ad49452ffeba64636ab8e644f04f646e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

module Gitlab
  module BackgroundMigration
    # A job to nullify `projects.creator_id` column of projects who creator
    # does not exist in `users` table anymore.
    class NullifyCreatorIdColumnOfOrphanedProjects < BatchedMigrationJob
      scope_to ->(relation) do
        relation.where.not(creator_id: nil)
                .joins('LEFT OUTER JOIN users ON users.id = projects.creator_id')
                .where(users: { id: nil })
                .allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/421843')
      end

      operation_name :update_all
      feature_category :groups_and_projects

      def perform
        ::Gitlab::Database.allow_cross_joins_across_databases(url:
          'https://gitlab.com/gitlab-org/gitlab/-/issues/421843') do
          each_sub_batch do |sub_batch|
            sub_batch.update_all(creator_id: nil)
          end
        end
      end
    end
  end
end