mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Remove group name validation case sensitivity
This commit is contained in:
23
db/migrate/20141216112341_resolve_duplicate_group_names.rb
Normal file
23
db/migrate/20141216112341_resolve_duplicate_group_names.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
class ResolveDuplicateGroupNames < ActiveRecord::Migration
|
||||
|
||||
def up
|
||||
results = Group.exec_sql 'SELECT id FROM groups
|
||||
WHERE name ILIKE
|
||||
(SELECT lower(name)
|
||||
FROM groups
|
||||
GROUP BY lower(name)
|
||||
HAVING count(*) > 1);'
|
||||
|
||||
groups = Group.where id: results.map { |r| r['id'] }
|
||||
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
|
||||
Reference in New Issue
Block a user