Class: Gitlab::BackgroundMigration::BackfillEnvironmentTiers
- Inherits:
-
BatchedMigrationJob
- Object
- BatchedMigrationJob
- Gitlab::BackgroundMigration::BackfillEnvironmentTiers
- Defined in:
- lib/gitlab/background_migration/backfill_environment_tiers.rb
Overview
This class backfills the ‘environments.tier` column by using `guess_tier` logic. Environments created after 13.10 already have a value, however, environments created before 13.10 don’t. See gitlab.com/gitlab-org/gitlab/-/issues/300741 for more information.
Constant Summary collapse
- PRODUCTION_TIER =
Equivalent to ‘Environment#guess_tier` pattern matching.
0
- STAGING_TIER =
1
- TESTING_TIER =
2
- DEVELOPMENT_TIER =
3
- OTHER_TIER =
4
- TIER_REGEXP_PAIR =
[ { tier: DEVELOPMENT_TIER, regexp: '(dev|review|trunk)' }, { tier: TESTING_TIER, regexp: '(test|tst|int|ac(ce|)pt|qa|qc|control|quality)' }, { tier: STAGING_TIER, regexp: '(st(a|)g|mod(e|)l|pre|demo|non)' }, { tier: PRODUCTION_TIER, regexp: '(pr(o|)d|live)' } ].freeze
Constants inherited from BatchedMigrationJob
Gitlab::BackgroundMigration::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
#perform ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gitlab/background_migration/backfill_environment_tiers.rb', line 26 def perform TIER_REGEXP_PAIR.each do |pair| each_sub_batch( batching_scope: ->(relation) { relation.where(tier: nil).where("name ~* '#{pair[:regexp]}'") } # rubocop:disable GitlabSecurity/SqlInjection ) do |sub_batch| sub_batch.update_all(tier: pair[:tier]) end end each_sub_batch(batching_scope: ->(relation) { relation.where(tier: nil) }) do |sub_batch| sub_batch.update_all(tier: OTHER_TIER) end end |