Class: Gitlab::BackgroundMigration::BackfillGroupPushRulesFromPushRulesWithIds

Inherits:
BatchedMigrationJob
  • Object
show all
Defined in:
lib/gitlab/background_migration/backfill_group_push_rules_from_push_rules_with_ids.rb

Constant Summary

Constants inherited from BatchedMigrationJob

Gitlab::BackgroundMigration::BatchedMigrationJob::DEFAULT_FEATURE_CATEGORY, Gitlab::BackgroundMigration::BatchedMigrationJob::MINIMUM_PAUSE_MS

Constants included from Database::DynamicModelHelpers

Database::DynamicModelHelpers::BATCH_SIZE

Instance Method Summary collapse

Methods inherited from BatchedMigrationJob

#batch_metrics, cursor, cursor?, cursor_columns, feature_category, #filter_batch, generic_instance, health_context_tables, #initialize, job_arguments, job_arguments_count, operation_name, scope_to, tables_to_check_for_vacuum

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

#backfill_group_push_rules_batch(sub_batch) ⇒ Object



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
46
# File 'lib/gitlab/background_migration/backfill_group_push_rules_from_push_rules_with_ids.rb', line 15

def backfill_group_push_rules_batch(sub_batch)
  connection.execute(<<~SQL)
    INSERT INTO group_push_rules (
      id, group_id, max_file_size, member_check, prevent_secrets, commit_committer_name_check,
      deny_delete_tag, reject_unsigned_commits, commit_committer_check, reject_non_dco_commits,
      commit_message_regex, branch_name_regex, commit_message_negative_regex, author_email_regex,
      file_name_regex, created_at, updated_at
    )
    SELECT
      pr.id, n.id as group_id, pr.max_file_size, pr.member_check, pr.prevent_secrets, pr.commit_committer_name_check,
      pr.deny_delete_tag, pr.reject_unsigned_commits, pr.commit_committer_check, pr.reject_non_dco_commits,
      pr.commit_message_regex, pr.branch_name_regex, pr.commit_message_negative_regex, pr.author_email_regex,
      pr.file_name_regex, pr.created_at, pr.updated_at
    FROM push_rules pr
    INNER JOIN namespaces n ON n.push_rule_id = pr.id
    WHERE pr.id BETWEEN #{sub_batch.min.id} AND #{sub_batch.max.id} AND n.type = 'Group'
    ON CONFLICT (id) DO UPDATE SET
      group_id = EXCLUDED.group_id,
      max_file_size = EXCLUDED.max_file_size,
      member_check = EXCLUDED.member_check,
      prevent_secrets = EXCLUDED.prevent_secrets,
      commit_committer_name_check = EXCLUDED.commit_committer_name_check,
      deny_delete_tag = EXCLUDED.deny_delete_tag,
      reject_unsigned_commits = EXCLUDED.reject_unsigned_commits,
      commit_committer_check = EXCLUDED.commit_committer_check,
      reject_non_dco_commits = EXCLUDED.reject_non_dco_commits,
      commit_message_regex = EXCLUDED.commit_message_regex, branch_name_regex = EXCLUDED.branch_name_regex,
      commit_message_negative_regex = EXCLUDED.commit_message_negative_regex,
      author_email_regex = EXCLUDED.author_email_regex, file_name_regex = EXCLUDED.file_name_regex,
      created_at = EXCLUDED.created_at, updated_at = EXCLUDED.updated_at;
  SQL
end

#performObject



9
10
11
12
13
# File 'lib/gitlab/background_migration/backfill_group_push_rules_from_push_rules_with_ids.rb', line 9

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