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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/background_migration/backfill_code_suggestions_namespace_settings.rb')
-rw-r--r--lib/gitlab/background_migration/backfill_code_suggestions_namespace_settings.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/gitlab/background_migration/backfill_code_suggestions_namespace_settings.rb b/lib/gitlab/background_migration/backfill_code_suggestions_namespace_settings.rb
new file mode 100644
index 00000000000..2d3bb4bbafa
--- /dev/null
+++ b/lib/gitlab/background_migration/backfill_code_suggestions_namespace_settings.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module BackgroundMigration
+ # This class sets default `code_suggestions` values on the namespace_settings table.
+ # For group namespace, set this to enabled.
+ # For user namespace, set this to disabled.
+ class BackfillCodeSuggestionsNamespaceSettings < BatchedMigrationJob
+ feature_category :code_suggestions
+ operation_name :update_all
+
+ TYPE_VALUE_PAIRS = [
+ { type: 'Group', value: true },
+ { type: 'User', value: false }
+ ].freeze
+
+ NAMESPACES_JOIN = <<~SQL
+ INNER JOIN namespaces
+ ON namespaces.id = namespace_settings.namespace_id
+ SQL
+
+ def perform
+ TYPE_VALUE_PAIRS.each do |pair|
+ each_sub_batch do |sub_batch|
+ sub_batch.joins(NAMESPACES_JOIN)
+ .where(namespaces: { type: pair[:type] })
+ .update_all(code_suggestions: pair[:value])
+ end
+ end
+ end
+ end
+ end
+end