Commit 1a5f2e17 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch 'project-topics-data-migration-cleanup' into 'master'

Clean up intermediate state during data migration of project topics

See merge request gitlab-org/gitlab!62066
parents 91ee6e53 91bbbd1f
...@@ -129,41 +129,15 @@ class Project < ApplicationRecord ...@@ -129,41 +129,15 @@ class Project < ApplicationRecord
after_create :check_repository_absence! after_create :check_repository_absence!
acts_as_ordered_taggable_on :topics acts_as_ordered_taggable_on :topics
# The 'tag_list' alias and the 'has_many' associations are required during the 'tags -> topics' migration # The 'tag_list' alias and the 'tags' association are required during the 'tags -> topics' migration
# TODO: eliminate 'tag_list', 'topic_taggings' and 'tags' in the further process of the migration # TODO: eliminate 'tag_list' and 'tags' in the further process of the migration
# https://gitlab.com/gitlab-org/gitlab/-/issues/331081 # https://gitlab.com/gitlab-org/gitlab/-/issues/328226
alias_attribute :tag_list, :topic_list alias_attribute :tag_list, :topic_list
has_many :topic_taggings, -> { includes(:tag).order("#{ActsAsTaggableOn::Tagging.table_name}.id") },
as: :taggable,
class_name: 'ActsAsTaggableOn::Tagging',
after_add: :dirtify_tag_list,
after_remove: :dirtify_tag_list
has_many :topics, -> { order("#{ActsAsTaggableOn::Tagging.table_name}.id") },
class_name: 'ActsAsTaggableOn::Tag',
through: :topic_taggings,
source: :tag
has_many :tags, -> { order("#{ActsAsTaggableOn::Tagging.table_name}.id") }, has_many :tags, -> { order("#{ActsAsTaggableOn::Tagging.table_name}.id") },
class_name: 'ActsAsTaggableOn::Tag', class_name: 'ActsAsTaggableOn::Tag',
through: :topic_taggings, through: :topic_taggings,
source: :tag source: :tag
# Overwriting 'topic_list' and 'topic_list=' is necessary to ensure functionality during the background migration [1].
# [1] https://gitlab.com/gitlab-org/gitlab/-/merge_requests/61237
# TODO: remove 'topic_list' and 'topic_list=' once the background migration is complete
# https://gitlab.com/gitlab-org/gitlab/-/issues/331081
def topic_list
# Return both old topics (context 'tags') and new topics (context 'topics')
tag_list_on('tags') + tag_list_on('topics')
end
def topic_list=(new_tags)
# Old topics with context 'tags' are added as new topics with context 'topics'
super(new_tags)
# Remove old topics with context 'tags'
set_tag_list_on('tags', '')
end
attr_accessor :old_path_with_namespace attr_accessor :old_path_with_namespace
attr_accessor :template_name attr_accessor :template_name
attr_writer :pipeline_status attr_writer :pipeline_status
......
...@@ -6889,31 +6889,6 @@ RSpec.describe Project, factory_default: :keep do ...@@ -6889,31 +6889,6 @@ RSpec.describe Project, factory_default: :keep do
expect(project.tags.map(&:name)).to match_array(%w[topic1 topic2 topic3]) expect(project.tags.map(&:name)).to match_array(%w[topic1 topic2 topic3])
end end
end end
context 'intermediate state during background migration' do
before do
project.taggings.first.update!(context: 'tags')
project.instance_variable_set("@tag_list", nil)
project.reload
end
it 'tag_list returns string array including old and new topics' do
expect(project.tag_list).to match_array(%w[topic1 topic2 topic3])
end
it 'tags returns old and new tag records' do
expect(project.tags.first.class.name).to eq('ActsAsTaggableOn::Tag')
expect(project.tags.map(&:name)).to match_array(%w[topic1 topic2 topic3])
expect(project.taggings.map(&:context)).to match_array(%w[tags topics topics])
end
it 'update tag_list adds new topics and removes old topics' do
project.update!(tag_list: 'topic1, topic2, topic3, topic4')
expect(project.tags.map(&:name)).to match_array(%w[topic1 topic2 topic3 topic4])
expect(project.taggings.map(&:context)).to match_array(%w[topics topics topics topics])
end
end
end end
def finish_job(export_job) def finish_job(export_job)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment