2020-04-02 00:15:28 +00:00
|
|
|
|
2020-04-06 02:50:30 +00:00
|
|
|
ENV['SCRYPT_MAX_TIME'] ||= "1"
|
2020-04-02 00:08:19 +00:00
|
|
|
class UpdatePasswordsToScrypt < ActiveRecord::Migration[6.0]
|
|
|
|
require 'scrypt'
|
|
|
|
|
|
|
|
def up
|
2020-04-06 02:50:30 +00:00
|
|
|
puts("SCRYPT_MAX_TIME=%s" % ENV['SCRYPT_MAX_TIME'])
|
2020-04-06 02:52:39 +00:00
|
|
|
puts("Migration takes about %0.0f seconds." % ENV['SCRYPT_MAX_TIME'].to_f*User.all.count*3)
|
2020-04-02 02:08:58 +00:00
|
|
|
SCrypt::Engine.calibrate!(max_time: ENV['SCRYPT_MAX_TIME'].to_f)
|
2020-04-02 00:08:19 +00:00
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
User.all.order(:id).each do |user|
|
2020-04-02 00:15:28 +00:00
|
|
|
user.team = nil unless user&.team&.present?
|
|
|
|
if user.valid?
|
|
|
|
user.update_password
|
|
|
|
user.save!
|
2020-04-06 02:50:30 +00:00
|
|
|
puts("User %s (%d) updated" % [user.username, user.id])
|
2020-04-02 00:15:28 +00:00
|
|
|
end
|
2020-04-02 00:08:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|