Don't use original ID as reaction ID during import

This commit is contained in:
Gerhard Schlager 2024-12-19 22:02:24 +01:00
parent 9c38b650fd
commit 33c7d52043
2 changed files with 27 additions and 7 deletions

View File

@ -120,6 +120,7 @@ class BulkImport::Base
chat_channel: 6,
chat_thread: 7,
chat_message: 8,
discourse_reactions_reaction: 9,
)
def create_migration_mappings_table
@ -309,6 +310,10 @@ class BulkImport::Base
@chat_message_mapping = load_index(MAPPING_TYPES[:chat_message])
@last_chat_message_id = last_id(Chat::Message)
puts "Loading reaction indexes..."
@discourse_reaction_mapping = load_index(MAPPING_TYPES[:discourse_reactions_reaction])
@last_discourse_reaction_id = last_id(DiscourseReactions::Reaction)
end
def use_bbcode_to_md?
@ -390,6 +395,11 @@ class BulkImport::Base
"SELECT setval('#{Chat::Message.sequence_name}', #{@last_chat_message_id})",
)
end
if @last_discourse_reaction_id > 0
@raw_connection.exec(
"SELECT setval('#{DiscourseReactions::Reaction.sequence_name}', #{@last_discourse_reaction_id})",
)
end
end
def group_id_from_imported_id(id)
@ -475,6 +485,10 @@ class BulkImport::Base
@chat_message_mapping[id.to_s]&.to_i
end
def discourse_reaction_id_from_original_id(id)
@discourse_reaction_mapping[id.to_s]&.to_i
end
GROUP_COLUMNS = %i[
id
name
@ -1174,7 +1188,7 @@ class BulkImport::Base
end
def create_reactions(rows, &block)
create_records(rows, "discourse_reactions_reaction", REACTION_COLUMNS, &block)
create_records_with_mapping(rows, "discourse_reactions_reaction", REACTION_COLUMNS, &block)
end
def process_group(group)
@ -1989,9 +2003,14 @@ class BulkImport::Base
end
def process_discourse_reactions_reaction(reaction)
reaction[:id] = @last_discourse_reaction_id += 1
reaction[:created_at] ||= NOW
reaction[:updated_at] ||= NOW
reaction[:reaction_users_count] ||= 0
@imported_records[reaction[:original_id].to_s] = reaction[:id]
@discourse_reaction_mapping[reaction[:original_id].to_s] = reaction[:id]
reaction
end

View File

@ -2972,16 +2972,17 @@ class BulkImport::Generic < BulkImport::Base
user_id = user_id_from_imported_id(row["user_id"])
post_id = post_id_from_imported_id(row["post_id"])
reaction_id = discourse_reaction_id_from_original_id(row["reaction_id"])
next if post_id.blank? || user_id.blank?
next unless existing_reaction_users.add?([row["reaction_id"], user_id, post_id])
next if post_id.blank? || user_id.blank? || reaction_id.blank?
next unless existing_reaction_users.add?([reaction_id, user_id, post_id])
{
reaction_id: row["reaction_id"],
user_id: user_id,
reaction_id:,
user_id:,
created_at: to_datetime(row["created_at"]),
updated_at: to_datetime(row["updated_at"]),
post_id: post_id,
post_id:,
}
end
@ -3014,7 +3015,7 @@ class BulkImport::Generic < BulkImport::Base
next unless existing_reactions.add?([post_id, row["reaction_value"]])
{
id: row["id"],
original_id: row["id"],
post_id: post_id,
reaction_type: reaction_type_id,
reaction_value: row["reaction_value"],