如何更新以前使用 gem attr_encrypted 未加密的现有记录。
我目前有text
一个名为的表中的列,AppointmentNote
它只是一个字符串。我现在想要一个名为note
加密的列(使用 attr_encrypted)。
我已经添加了列
encrypted_note
encrypted_note_iv
当我AppointmentNote.create(note: "blah")
正确加密时,这很好用,并且对该记录的任何进一步更新都很好用。
问题在于迁移之前创建的记录。如何将列中的所有数据迁移text
到新的加密列encrypted_note
和encrypted_note_iv
这是模型
class AppointmentNote < ApplicationRecord
attr_encrypted_options.merge!(encode: true)
attr_encrypted :note, key: SOME_KEY
...
end
如果我做我认为明显的解决方案就是简单地回滚
AppointmentNote.first.update(note: "rawr")
谢谢