Files
gitlab-foss/lib/gitlab/background_migration/populate_topics_slug_column.rb
2024-02-13 03:10:07 +00:00

26 lines
672 B
Ruby

# frozen_string_literal: true
module Gitlab
module BackgroundMigration
class PopulateTopicsSlugColumn < BatchedMigrationJob
feature_category :groups_and_projects
scope_to ->(relation) { relation.where(slug: nil) }
operation_name :populate_topics_slug_column
def perform
each_sub_batch do |sub_batch|
sub_batch.each { |topic| topic.update! slug: clean_name(topic) }
end
end
private
def clean_name(topic)
cleaned_name = ::Gitlab::Slug::Path.new(topic.name).generate
Gitlab::Utils::Uniquify.new.string(cleaned_name) { |s| topic.class.find_by_slug(s) }
end
end
end
end