Commit 51734609 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'minor-user-mentions-migrations-refactor' into 'master'

Refactor background migration code for user mentions

See merge request gitlab-org/gitlab!23951
parents d27596b2 24716da3
...@@ -47,6 +47,10 @@ describe Gitlab::BackgroundMigration::UserMentions::CreateResourceUserMention do ...@@ -47,6 +47,10 @@ describe Gitlab::BackgroundMigration::UserMentions::CreateResourceUserMention do
title_html: "epic title @#{author.username}", description: description_mentions) title_html: "epic title @#{author.username}", description: description_mentions)
end end
it 'has correct no_quote_columns' do
expect(Gitlab::BackgroundMigration::UserMentions::Models::Epic.no_quote_columns).to match([:note_id, :epic_id])
end
it 'migrates mentions' do it 'migrates mentions' do
join = MigrateEpicMentionsToDb::JOIN join = MigrateEpicMentionsToDb::JOIN
conditions = MigrateEpicMentionsToDb::QUERY_CONDITIONS conditions = MigrateEpicMentionsToDb::QUERY_CONDITIONS
......
...@@ -24,14 +24,11 @@ module Gitlab ...@@ -24,14 +24,11 @@ module Gitlab
mentions << record.build_mention_values mentions << record.build_mention_values
end end
no_quote_columns = [:note_id]
no_quote_columns << resource_user_mention_model.resource_foreign_key
Gitlab::Database.bulk_insert( Gitlab::Database.bulk_insert(
resource_user_mention_model.table_name, resource_user_mention_model.table_name,
mentions, mentions,
return_ids: true, return_ids: true,
disable_quote: no_quote_columns, disable_quote: resource_model.no_quote_columns,
on_conflict: :do_nothing on_conflict: :do_nothing
) )
end end
......
# frozen_string_literal: true
module Gitlab
module BackgroundMigration
module UserMentions
module Models
# Extract common no_quote_columns method used in determining the columns that do not need
# to be quoted for corresponding models
module MentionableMigrationMethods
extend ::ActiveSupport::Concern
class_methods do
def no_quote_columns
[
:note_id,
user_mention_model.resource_foreign_key
]
end
end
end
end
end
end
end
...@@ -8,6 +8,7 @@ module Gitlab ...@@ -8,6 +8,7 @@ module Gitlab
class Epic < ActiveRecord::Base class Epic < ActiveRecord::Base
include IsolatedMentionable include IsolatedMentionable
include CacheMarkdownField include CacheMarkdownField
include MentionableMigrationMethods
attr_mentionable :title, pipeline: :single_line attr_mentionable :title, pipeline: :single_line
attr_mentionable :description attr_mentionable :description
......
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