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

disable_legacy_open_source_licence_for_recent_public_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: c4ce88b940411ae1ba1a7e128a77abf59e8e60d5 (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
# frozen_string_literal: true

module Gitlab
  module BackgroundMigration
    # Set `project_settings.legacy_open_source_license_available` to false for public projects created after 17/02/2022
    class DisableLegacyOpenSourceLicenceForRecentPublicProjects < ::Gitlab::BackgroundMigration::BatchedMigrationJob
      PUBLIC = 20
      THRESHOLD_DATE = '2022-02-17 09:00:00'

      operation_name :disable_legacy_open_source_licence_for_recent_public_projects
      feature_category :database

      # Migration only version of `project_settings` table
      class ProjectSetting < ApplicationRecord
        self.table_name = 'project_settings'
      end

      def perform
        each_sub_batch(
          batching_scope: ->(relation) {
            relation.where(visibility_level: PUBLIC).where('created_at >= ?', THRESHOLD_DATE)
          }
        ) do |sub_batch|
          ProjectSetting.where(project_id: sub_batch)
                        .where(legacy_open_source_license_available: true)
                        .update_all(legacy_open_source_license_available: false)
        end
      end
    end
  end
end