mirror of
https://gitlab.com/gitlab-org/gitlab-foss.git
synced 2025-07-25 16:03:48 +00:00
34 lines
940 B
Ruby
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
|