Skip to content

FIX: Stop silently dropping first two rows during load_mapping #33076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions migrations/lib/importer/shared_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,23 @@ def load_set(sql)
def load_mapping(sql)
rows = @discourse_db.query_array(sql)

if rows.first && rows.first.size > 2
rows.to_h { |key, *values| [key, *values] }
else
rows.to_h
end
# While rows is an enumerator, it's not fully compliant, it does not
# rewind on #first, #peek, #any?, etc.
# So we need to hold on to first_row for use later
first_row = rows.first

return {} if first_row.nil?

has_multiple_values = first_row.size > 2
result =
if has_multiple_values
rows.to_h { |key, *values| [key, values] }
else
rows.to_h
end

result[first_row[0]] = has_multiple_values ? first_row[1..] : first_row[1]
result
end

def load(type)
Expand Down