From 5830ab702abda97945d379db2f4d773e4b4024ce Mon Sep 17 00:00:00 2001 From: Jonas Waelter Date: Wed, 19 May 2021 08:42:54 +0200 Subject: [PATCH 1/3] Clean up intermediate state during project topics migration Changelog: removed --- app/models/project.rb | 32 +++----------------------------- spec/models/project_spec.rb | 25 ------------------------- 2 files changed, 3 insertions(+), 54 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 4bc16771323bc3..16a3f1ba649792 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -129,41 +129,15 @@ class Project < ApplicationRecord after_create :check_repository_absence! acts_as_ordered_taggable_on :topics - # The 'tag_list' alias and the 'has_many' associations are required during the 'tags -> topics' migration - # TODO: eliminate 'tag_list', 'topic_taggings' and 'tags' in the further process of the migration - # https://gitlab.com/gitlab-org/gitlab/-/issues/331081 + # The 'tag_list' alias and the 'tags' association are required during the 'tags -> topics' migration + # TODO: eliminate 'tag_list' and 'tags' in the further process of the migration + # https://gitlab.com/gitlab-org/gitlab/-/issues/328226 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") }, class_name: 'ActsAsTaggableOn::Tag', through: :topic_taggings, 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 :template_name attr_writer :pipeline_status diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 8e606a00144fdc..7b9eed7fb25579 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -6888,31 +6888,6 @@ def enable_lfs expect(project.tags.map(&:name)).to match_array(%w[topic1 topic2 topic3]) 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 def finish_job(export_job) -- GitLab From 56a0a8f2ed305b8a86fa4dd6136dd6ced06e95b1 Mon Sep 17 00:00:00 2001 From: Jonas Waelter Date: Wed, 19 May 2021 08:56:11 +0200 Subject: [PATCH 2/3] Add changelog entry --- .../unreleased/project-topics-data-migration-cleanup.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelogs/unreleased/project-topics-data-migration-cleanup.yml diff --git a/changelogs/unreleased/project-topics-data-migration-cleanup.yml b/changelogs/unreleased/project-topics-data-migration-cleanup.yml new file mode 100644 index 00000000000000..7b4072bae2dd1d --- /dev/null +++ b/changelogs/unreleased/project-topics-data-migration-cleanup.yml @@ -0,0 +1,5 @@ +--- +title: Clean up intermediate state during data migration of project topics +merge_request: 62066 +author: Jonas Wälter @wwwjon +type: removed -- GitLab From 0805fc50b8be7fe25e82d123e4ee99858d790a10 Mon Sep 17 00:00:00 2001 From: Jonas Waelter Date: Tue, 25 May 2021 10:46:43 +0200 Subject: [PATCH 3/3] Revert "Add changelog entry" This reverts commit 56a0a8f2ed305b8a86fa4dd6136dd6ced06e95b1. --- .../unreleased/project-topics-data-migration-cleanup.yml | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 changelogs/unreleased/project-topics-data-migration-cleanup.yml diff --git a/changelogs/unreleased/project-topics-data-migration-cleanup.yml b/changelogs/unreleased/project-topics-data-migration-cleanup.yml deleted file mode 100644 index 7b4072bae2dd1d..00000000000000 --- a/changelogs/unreleased/project-topics-data-migration-cleanup.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -title: Clean up intermediate state during data migration of project topics -merge_request: 62066 -author: Jonas Wälter @wwwjon -type: removed -- GitLab