0

Earlier my code was having encryption methodology using 'attr_encrypted' but later I changed my mind to integrate vault for encryption/decryption. So I want to understand how can I migrate my old saved encrypted data to new one.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120

1 Answers1

0

Seems pretty straightforward. If you have, say, field ssn

attr_encrypted :ssn

You can create a second field, now backed by vault

vault_attribute :ssn2

Then iterate your records and set ssn2 value to that of ssn. This should take care of data migration.

After that is done, you might want to delete ssn's backing fields and rename ssn2's backing field(s), so that rest of your code continues to use name ssn.

Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
  • Need a bit correction, I want to use both the mechanism, if someone data is already saved using attr_encrypted then use that and vault for new user or any old user is updating their data. – Rahul Tibrewal Nov 27 '18 at 11:16
  • @RahulTibrewal: that's a different question. – Sergio Tulentsev Nov 27 '18 at 11:18
  • I have added a new question, can you please have a look on it? https://stackoverflow.com/questions/53498689/upgrading-from-attr-encrypted-and-vault-rails-for-same-key – Rahul Tibrewal Nov 27 '18 at 11:30