Update more reasonable/helpful scrypt migration

This commit is contained in:
Ari Timonen 2020-04-06 05:50:30 +03:00
parent c3ceb7853d
commit 4da3f38d25
2 changed files with 7 additions and 1 deletions

View file

@ -3,6 +3,9 @@
# Development-specific ENV variables, loaded after .env and before .env*local
# Add changes only specific to dev. env.
# Scrypt max time
SCRYPT_MAX_TIME=0.005
# These are
RACK_ENV=development
RAILS_ENV=development

View file

@ -1,9 +1,11 @@
ENV['SCRYPT_MAX_TIME'] ||= "0.03"
ENV['SCRYPT_MAX_TIME'] ||= "1"
class UpdatePasswordsToScrypt < ActiveRecord::Migration[6.0]
require 'scrypt'
def up
puts("SCRYPT_MAX_TIME=%s" % ENV['SCRYPT_MAX_TIME'])
puts("Migration takes about %0.0f seconds." % ENV['SCRYPT_MAX_TIME'].to_f*User.all.count)
SCrypt::Engine.calibrate!(max_time: ENV['SCRYPT_MAX_TIME'].to_f)
ActiveRecord::Base.transaction do
User.all.order(:id).each do |user|
@ -11,6 +13,7 @@ class UpdatePasswordsToScrypt < ActiveRecord::Migration[6.0]
if user.valid?
user.update_password
user.save!
puts("User %s (%d) updated" % [user.username, user.id])
end
end
end