Files
gitlab-foss/lib/gitlab/background_migration/backfill_onboarding_status_role.rb
2025-04-09 15:18:25 +00:00

34 lines
940 B
Ruby

# frozen_string_literal: true
module Gitlab
module BackgroundMigration
class BackfillOnboardingStatusRole < BatchedMigrationJob
operation_name :backfill_onboarding_status_role # This is used as the key on collecting metrics
feature_category :onboarding
scope_to ->(relation) { relation.where.not(role: nil) }
class UserDetail < ApplicationRecord
self.table_name = :user_details
belongs_to :user
end
def perform
each_sub_batch do |sub_batch|
UserDetail
.where(user: sub_batch)
.where("(onboarding_status->'role') is null")
.update_all(
"onboarding_status = jsonb_set(
COALESCE(onboarding_status, '{}'::jsonb),'{role}',to_jsonb(
(SELECT role FROM users WHERE users.id = user_details.user_id)
)
)"
)
end
end
end
end
end