mirror of
https://gitlab.com/gitlab-org/gitlab-foss.git
synced 2025-08-01 16:04:19 +00:00
26 lines
672 B
Ruby
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
|