Closed nattfodd closed 6 years ago
@nattfodd looks great indeed — in fact it might be more useful if we separate the data migration scheme and the attr_encryption “processor”, for example, so when one day we switch to another non-attr_encryption gem, we can still take advantage of the data migration scheme!
Do you think it fits the scope of Transcryptor
gem? Maybe it makes sense to extract migration logic into small separate gem and use it in transcryptor?
Yes that’s what I meant too. Feel free to proceed.
@nattfodd I believe these enhancements can be implemented after this PR is merged:
attr_encryptor
into a "transform processor" that is used to perform the migrationsattr_encryptor
, e.g., removing encryption of a column, adding encryption to a column.I believe the PR is ready to be merged (besides those nasty hound comments, which is difficult to fix).
Having direction from unencrypted to encrypted and vice versa isn't still clear for me, since encrypted field is called encrypted_ssn
in the database, and it would be weird to have raw unencrypted value in the column with such name. Same for universal
migrations.
Let's discuss it in a different Pull Request when it will be subject to discuss.
@nattfodd sounds good, please feel free to merge it with rebase.
Regarding unencrypted to encrypted, I suspect the following naming pairs make better sense?
Data column | Version column |
---|---|
ssn | ssn_version |
encrypted_ssn | encrypted_ssn_version |
So the database will:
:ssn
column:encrypted_ssn
, :encrypted_ssn_version
columns (and other necessary attr_encrypted columns) (and run it):ssn
data to :encrypted_ssn
Perhaps something like this is reasonable?
@nattfodd sounds good, please feel free to merge it with rebase.
I don't have access to write to the repository :)
Hmm.. I checked settings and it shouldn't be the case though. Anyway I'll merge it here.
Ha, just found out why 😉 Fixed.
This pull request addresses the following issues: https://github.com/riboseinc/transcryptor/issues/33, https://github.com/riboseinc/transcryptor/issues/24
Idea
To make this happen you need to create a column, that contains current version of the encrypted field. For example, if you have
attr_encrypted :ssn
, you need to create in your table another column:ssn_version
, with some default value - let it be20180401000000
for example.Assuming, you want to change encryption now. You create a new initializer file
config/initializers/transcryptor.rb
. And describe there the history of your changes:Complete example of usage can be found here: https://github.com/nattfodd/transcryptor_sample_app/pull/1/files
Pros:
Transcryptor
)***_version
field to perform as many migrations, as needTODOs:
attr_encrypted
default behaviour