Update scrypt migration

This commit is contained in:
Ari Timonen 2020-04-02 03:15:28 +03:00
parent af5b4140dd
commit 7ae3487d59
2 changed files with 9 additions and 3 deletions

View file

@ -12,6 +12,7 @@ APP_SECRET=randomstringhere
# SCrypt::Engine.calibrate!(max_mem: 16 * 1024 * 1024) # SCrypt::Engine.calibrate!(max_mem: 16 * 1024 * 1024)
# SCrypt::Engine.generate_salt # SCrypt::Engine.generate_salt
SCRYPT_SALT_OPTS= SCRYPT_SALT_OPTS=
SCRYPT_MAX_TIME=1
# Since this is inside Docker container, it doesn't really matter # Since this is inside Docker container, it doesn't really matter
DEPLOY_PATH=/var/www DEPLOY_PATH=/var/www

View file

@ -1,14 +1,19 @@
ENV['SCRYPT_MAX_TIME'] ||= "0.03"
class UpdatePasswordsToScrypt < ActiveRecord::Migration[6.0] class UpdatePasswordsToScrypt < ActiveRecord::Migration[6.0]
require 'scrypt' require 'scrypt'
require 'user' require 'user'
def up def up
SCrypt::Engine.calibrate!(max_time: 0.03) SCrypt::Engine.calibrate!(max_time: ENV['SCRYPT_MAX_TIME'])
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
User.all.order(:id).each do |user| User.all.order(:id).each do |user|
user.team = nil unless user&.team&.present?
if user.valid?
user.update_password user.update_password
user.save! user.save!
end end
end end
end end
end end
end