0

I'm adding encryption using the attr_encrypted gem. Essentially all I have to do is add the gem, and rename my columns to have a prefix of encrypted_column before adding the line:

  attr_encrypted :reply, key: ENV["ANSWER_CRYPT_KEY"]

to my model. Now this works all and well, however I'm getting ready to push this to production, and will have some issues, because the values there are not encrypted - is there a command I can run in my rails c to loop over them and encrypt them?

2 Answers2

0

I would advise going through an intermediate step, by renaming the reply column to old_reply. You can run a migration to do that:

def up
  rename_column :your_table, :reply, :old_reply

  Model.reset_column_information
  Model.find_each do |instance|
    model.reply = model.old_reply #this will set the encrypted_reply based on attr_encrypted
    model.save!
  end
end

Once you are sure that all the encrypted values are set, you can run another migration to remove old_reply

AbM
  • 7,326
  • 2
  • 25
  • 28
0

You also don't need to rename columns in the database; instead you can use :attribute option of the attr_encrypted gem. For reference you can have a look at its documentation here.

Swaps
  • 1,450
  • 24
  • 31