From b5131f94d520fb3acb35893fd750510c32c06ed0 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 3 Jun 2013 18:53:25 +0200 Subject: [PATCH] Add rake for encrypting columns in the DB --- lib/tasks/encyrpt_all_data.rake | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lib/tasks/encyrpt_all_data.rake diff --git a/lib/tasks/encyrpt_all_data.rake b/lib/tasks/encyrpt_all_data.rake new file mode 100644 index 00000000..3d15d1de --- /dev/null +++ b/lib/tasks/encyrpt_all_data.rake @@ -0,0 +1,31 @@ +namespace :db do + task :encrypt_all_columns do + require 'travis' + Travis::Database.connect + + to_encrypt = { + Request => [:token], + SslKey => [:private_key], + Token => [:token], + User => [:github_oauth_token] + } + + encrypted_column = Travis::Model::EncryptedColumn.new + to_encrypt.each do |model, column_names| + model.find_in_batches do |records| + ActiveRecord::Base.transaction do + records.each do |record| + column_names.each do |column| + puts "Encrypting #{model}##{column} (id: #{record.id})" + + data = record.send(column) + if encrypted_column.encrypt?(data) + record.update_column(column, encrypted_column.encrypt(data)) + end + end + end + end + end + end + end +end