Commit a6b60fee authored by Etienne Baqué's avatar Etienne Baqué Committed by Stan Hu

Iterating through token to encrypt with find_each

parent 3e48d419
...@@ -9,7 +9,7 @@ class EncryptDeployTokensTokens < ActiveRecord::Migration[5.1] ...@@ -9,7 +9,7 @@ class EncryptDeployTokensTokens < ActiveRecord::Migration[5.1]
def up def up
say_with_time("Encrypting tokens from deploy_tokens") do say_with_time("Encrypting tokens from deploy_tokens") do
DeploymentTokens.where('token_encrypted is NULL AND token IS NOT NULL').find_each do |deploy_token| DeploymentTokens.where('token_encrypted is NULL AND token IS NOT NULL').find_each(batch_size: 10000) do |deploy_token|
token_encrypted = Gitlab::CryptoHelper.aes256_gcm_encrypt(deploy_token.token) token_encrypted = Gitlab::CryptoHelper.aes256_gcm_encrypt(deploy_token.token)
deploy_token.update!(token_encrypted: token_encrypted) deploy_token.update!(token_encrypted: token_encrypted)
end end
...@@ -18,7 +18,7 @@ class EncryptDeployTokensTokens < ActiveRecord::Migration[5.1] ...@@ -18,7 +18,7 @@ class EncryptDeployTokensTokens < ActiveRecord::Migration[5.1]
def down def down
say_with_time("Decrypting tokens from deploy_tokens") do say_with_time("Decrypting tokens from deploy_tokens") do
DeploymentTokens.where('token_encrypted IS NOT NULL AND token IS NULL').find_each do |deploy_token| DeploymentTokens.where('token_encrypted IS NOT NULL AND token IS NULL').find_each(batch_size: 10000) do |deploy_token|
token = Gitlab::CryptoHelper.aes256_gcm_decrypt(deploy_token.token_encrypted) token = Gitlab::CryptoHelper.aes256_gcm_decrypt(deploy_token.token_encrypted)
deploy_token.update!(token: token) deploy_token.update!(token: token)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment