start encoding candidate emails - completes #57

This commit is contained in:
Mark Moser
2016-08-26 16:03:55 -05:00
parent 8269bb9e5c
commit 229ebf1380
7 changed files with 123 additions and 9 deletions

View File

@ -0,0 +1,26 @@
class EncodeCandidateEmails < ActiveRecord::Migration[5.0]
def change
sql = "select id, email from candidates;"
candidates = ActiveRecord::Base.connection.execute(sql).to_h
candidates.each do |id, email|
sql = if base64?(email)
# going down - decrypt
"UPDATE candidates set email = '#{CryptSerializer.load email}' WHERE id = #{id};"
else
# going up - encrypt emails
"UPDATE candidates set email = '#{CryptSerializer.dump email}' WHERE id = #{id};"
end
ActiveRecord::Base.connection.execute(sql)
end
end
private
def base64? string
Base64.urlsafe_decode64 string
true
rescue ArgumentError
false
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160824183159) do
ActiveRecord::Schema.define(version: 20160826200610) do
create_table "answers", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.integer "candidate_id"