mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 02:40:53 -06:00
30990006a9
This reduces chances of errors where consumers of strings mutate inputs and reduces memory usage of the app. Test suite passes now, but there may be some stuff left, so we will run a few sites on a branch prior to merging
26 lines
707 B
Ruby
26 lines
707 B
Ruby
# frozen_string_literal: true
|
|
|
|
class ResolveDuplicateGroupNames < ActiveRecord::Migration[4.2]
|
|
|
|
def up
|
|
results = DB.query_single 'SELECT id FROM groups
|
|
WHERE name ILIKE
|
|
(SELECT lower(name)
|
|
FROM groups
|
|
GROUP BY lower(name)
|
|
HAVING count(*) > 1);'
|
|
|
|
groups = Group.where id: results
|
|
groups.group_by { |g| g.name.downcase }.each do |key, value|
|
|
value.each_with_index do |dup, index|
|
|
dup.update! name: "#{dup.name[0..18]}_#{index + 1}" if index > 0
|
|
end
|
|
end
|
|
end
|
|
|
|
def down
|
|
# does not reverse changes
|
|
end
|
|
|
|
end
|