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

update_delayed_project_removal_to_null_for_user_namespaces.rb « background_migration « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a7faa5703da496b7eae692d7b82873a38ba7b5b5 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true

module Gitlab
  module BackgroundMigration
    # This class is used to update the delayed_project_removal column
    # for user namespaces of the namespace_settings table.
    class UpdateDelayedProjectRemovalToNullForUserNamespaces < Gitlab::BackgroundMigration::BatchedMigrationJob
      # Migration only version of `namespace_settings` table
      class NamespaceSetting < ::ApplicationRecord
        self.table_name = 'namespace_settings'
      end

      operation_name :set_delayed_project_removal_to_null_for_user_namespace
      feature_category :database

      def perform
        each_sub_batch do |sub_batch|
          set_delayed_project_removal_to_null_for_user_namespace(sub_batch)
        end
      end

      private

      def set_delayed_project_removal_to_null_for_user_namespace(relation)
        NamespaceSetting.connection.execute(
          <<~SQL
            UPDATE namespace_settings
            SET delayed_project_removal = NULL
            WHERE
              namespace_settings.namespace_id IN (
                SELECT
                  namespace_settings.namespace_id
                FROM
                  namespace_settings
                  INNER JOIN namespaces ON namespaces.id = namespace_settings.namespace_id
                WHERE
                  namespaces.id IN (#{relation.select(:namespace_id).to_sql})
                  AND namespaces.type = 'User'
                  AND namespace_settings.delayed_project_removal = FALSE)
        SQL
        )
      end
    end
  end
end