add fix script for user names

This commit is contained in:
r888888888
2017-03-06 16:56:23 -08:00
parent 51c752be2f
commit 26267cd238
2 changed files with 14 additions and 0 deletions

View File

@@ -1,5 +1,7 @@
class UserNameValidator < ActiveModel::EachValidator
def validate_each(rec, attr, value)
name = value
rec.errors[attr] << "already exists" if User.find_by_name(name).present?
rec.errors[attr] << "must be 2 to 100 characters long" if !name.length.between?(2, 100)
rec.errors[attr] << "cannot have whitespace or colons" if name =~ /[[:space:]]|:/

View File

@@ -0,0 +1,12 @@
#!/usr/bin/env ruby
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment'))
ActiveRecord::Base.connection.execute("set statement_timeout = 0")
User.where("name like ?", "% %").find_each do |user|
print "repairing #{user.name} -> "
user.name = user.name.gsub(/[[:space:]]/, "_")
user.save
puts user.name
end