Class: Gitlab::BackgroundMigration::AddProjectsEmailsEnabledColumnData

Inherits:
BatchedMigrationJob show all
Defined in:
lib/gitlab/background_migration/add_projects_emails_enabled_column_data.rb

Overview

Iterates through the Projects table and attempts to set the opposite of the value of the column “emails_disabled” to a new column in project_settings called emails_enabled

Defined Under Namespace

Classes: ProjectSetting

Constant Summary

Constants inherited from BatchedMigrationJob

BatchedMigrationJob::DEFAULT_FEATURE_CATEGORY

Constants included from Database::DynamicModelHelpers

Database::DynamicModelHelpers::BATCH_SIZE

Instance Method Summary collapse

Methods inherited from BatchedMigrationJob

#batch_metrics, feature_category, #filter_batch, generic_instance, #initialize, job_arguments, job_arguments_count, operation_name, scope_to

Methods included from Database::DynamicModelHelpers

#define_batchable_model, #each_batch, #each_batch_range

Constructor Details

This class inherits a constructor from Gitlab::BackgroundMigration::BatchedMigrationJob

Instance Method Details

#performObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gitlab/background_migration/add_projects_emails_enabled_column_data.rb', line 17

def perform
  each_sub_batch do |sub_batch|
    plucked_list = sub_batch.where('NOT emails_disabled IS NULL').pluck(:id, :emails_disabled)
    next if plucked_list.empty?

    ApplicationRecord.connection.execute <<~SQL
            UPDATE project_settings
            SET emails_enabled=NOT subquery.emails_enabled
            FROM (SELECT * FROM (#{Arel::Nodes::ValuesList.new(plucked_list).to_sql}) AS updates(project_id, emails_enabled)) AS subquery
            WHERE project_settings.project_id=subquery.project_id
    SQL
  end
end