Commit 3c379e96 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'reschedule_ExtractProjectTopicsIntoSeparateTable_2' into 'master'

Reschedule 'ExtractProjectTopicsIntoSeparateTable' bg migration (2)

See merge request gitlab-org/gitlab!70018
parents 483818d9 56dd119f
# frozen_string_literal: true
class RescheduleExtractProjectTopicsIntoSeparateTable2 < Gitlab::Database::Migration[1.0]
MIGRATION = 'ExtractProjectTopicsIntoSeparateTable'
DELAY_INTERVAL = 4.minutes
disable_ddl_transaction!
def up
requeue_background_migration_jobs_by_range_at_intervals(MIGRATION, DELAY_INTERVAL)
end
def down
# no-op
end
end
834825de758314db01a3daa2d2b943c11751553705c4dd078f2087b9ec6ff7f7
\ No newline at end of file
......@@ -33,11 +33,15 @@ module Gitlab
def perform(start_id, stop_id)
Tagging.includes(:tag).where(taggable_type: 'Project', id: start_id..stop_id).each do |tagging|
if Project.exists?(id: tagging.taggable_id)
if Project.exists?(id: tagging.taggable_id) && tagging.tag
begin
topic = Topic.find_or_create_by(name: tagging.tag.name)
project_topic = ProjectTopic.find_or_create_by(project_id: tagging.taggable_id, topic: topic)
tagging.delete if project_topic.persisted?
rescue StandardError => e
Gitlab::ErrorTracking.log_exception(e, tagging_id: tagging.id)
end
else
tagging.delete
end
......
......@@ -22,8 +22,9 @@ RSpec.describe Gitlab::BackgroundMigration::ExtractProjectTopicsIntoSeparateTabl
other_tagging = taggings.create!(taggable_type: 'Other', taggable_id: project.id, context: 'topics', tag_id: tag_1.id)
tagging_3 = taggings.create!(taggable_type: 'Project', taggable_id: project.id, context: 'topics', tag_id: tag_3.id)
tagging_4 = taggings.create!(taggable_type: 'Project', taggable_id: -1, context: 'topics', tag_id: tag_1.id)
tagging_5 = taggings.create!(taggable_type: 'Project', taggable_id: project.id, context: 'topics', tag_id: -1)
subject.perform(tagging_1.id, tagging_4.id)
subject.perform(tagging_1.id, tagging_5.id)
# Tagging records
expect { tagging_1.reload }.to raise_error(ActiveRecord::RecordNotFound)
......@@ -31,6 +32,7 @@ RSpec.describe Gitlab::BackgroundMigration::ExtractProjectTopicsIntoSeparateTabl
expect { other_tagging.reload }.not_to raise_error(ActiveRecord::RecordNotFound)
expect { tagging_3.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { tagging_4.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { tagging_5.reload }.to raise_error(ActiveRecord::RecordNotFound)
# Topic records
topic_1 = topics.find_by(name: 'Topic1')
......
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