Migration from attr_encrypted to vault-rails gem

127 views Asked by At

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.

1

There are 1 answers

3
Sergio Tulentsev On

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.