Commit e83c9223 authored by Thong Kuah's avatar Thong Kuah

Merge branch 'reschedule_ExtractProjectTopicsIntoSeparateTable' into 'master'

Reschedule 'ExtractProjectTopicsIntoSeparateTable' background migration

See merge request gitlab-org/gitlab!69199
parents a998bacb 7f45515d
# frozen_string_literal: true
class RescheduleExtractProjectTopicsIntoSeparateTable < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
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
84a68304f95ae04b85625c214b28a251014582fb142390ff3df8ea6d6f0947e1
\ No newline at end of file
......@@ -26,12 +26,21 @@ module Gitlab
belongs_to :topic
end
# Temporary AR table for projects
class Project < ActiveRecord::Base
self.table_name = 'projects'
end
def perform(start_id, stop_id)
Tagging.includes(:tag).where(taggable_type: 'Project', id: start_id..stop_id).each do |tagging|
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?
if Project.exists?(id: tagging.taggable_id)
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?
else
tagging.delete
end
end
mark_job_as_succeeded(start_id, stop_id)
......
......@@ -21,14 +21,16 @@ RSpec.describe Gitlab::BackgroundMigration::ExtractProjectTopicsIntoSeparateTabl
tagging_2 = taggings.create!(taggable_type: 'Project', taggable_id: project.id, context: 'topics', tag_id: tag_2.id)
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)
subject.perform(tagging_1.id, tagging_3.id)
subject.perform(tagging_1.id, tagging_4.id)
# Tagging records
expect { tagging_1.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { tagging_2.reload }.to raise_error(ActiveRecord::RecordNotFound)
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)
# 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