start encoding candidate emails - completes #57
This commit is contained in:
26
db/migrate/20160826200610_encode_candidate_emails.rb
Normal file
26
db/migrate/20160826200610_encode_candidate_emails.rb
Normal 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
|
@ -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"
|
||||
|
Reference in New Issue
Block a user