20160307085545_warn_about_duplicate_usernames.rb 804 B

123456789101112131415161718192021
  1. class WarnAboutDuplicateUsernames < ActiveRecord::Migration[4.2]
  2. def up
  3. names = User.group('LOWER(username)').having('count(*) > 1').pluck('LOWER(username)')
  4. if names.length > 0
  5. puts "-----------------------------------------------------"
  6. puts "--------------------- WARNiNG -----------------------"
  7. puts "-------- Found users with duplicate usernames -------"
  8. puts "-----------------------------------------------------"
  9. puts "For the users to log in using their username they have to change it to a unique name"
  10. names.each do |name|
  11. puts
  12. puts "'#{name}' is used multiple times:"
  13. User.where(['LOWER(username) = ?', name]).each do |u|
  14. puts "#{u.id}\t#{u.email}"
  15. end
  16. end
  17. puts
  18. puts
  19. end
  20. end
  21. end