From 7ae3487d5938b1a594034af1ba51064080cce4de Mon Sep 17 00:00:00 2001 From: Ari Timonen Date: Thu, 2 Apr 2020 03:15:28 +0300 Subject: [PATCH] Update scrypt migration --- .env.example | 1 + .../20200401031518_update_passwords_to_scrypt.rb | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 923480e..9a734d6 100644 --- a/.env.example +++ b/.env.example @@ -12,6 +12,7 @@ APP_SECRET=randomstringhere # SCrypt::Engine.calibrate!(max_mem: 16 * 1024 * 1024) # SCrypt::Engine.generate_salt SCRYPT_SALT_OPTS= +SCRYPT_MAX_TIME=1 # Since this is inside Docker container, it doesn't really matter DEPLOY_PATH=/var/www diff --git a/db/migrate/20200401031518_update_passwords_to_scrypt.rb b/db/migrate/20200401031518_update_passwords_to_scrypt.rb index 4610daf..da48d17 100644 --- a/db/migrate/20200401031518_update_passwords_to_scrypt.rb +++ b/db/migrate/20200401031518_update_passwords_to_scrypt.rb @@ -1,13 +1,18 @@ + +ENV['SCRYPT_MAX_TIME'] ||= "0.03" class UpdatePasswordsToScrypt < ActiveRecord::Migration[6.0] require 'scrypt' require 'user' def up - SCrypt::Engine.calibrate!(max_time: 0.03) + SCrypt::Engine.calibrate!(max_time: ENV['SCRYPT_MAX_TIME']) ActiveRecord::Base.transaction do User.all.order(:id).each do |user| - user.update_password - user.save! + user.team = nil unless user&.team&.present? + if user.valid? + user.update_password + user.save! + end end end end