问题
由于这个问题,我不得不将我的 RoR 应用程序升级到 Rails 7 。进行此升级时,由于 Rails 使用本机解密尝试解密字段,因此无法再读取使用Lockbox gem加密的 db 列。我在 GitHub 上将它作为一个问题发布,但我也想知道是否有其他人有解决方案将数据从一种加密格式迁移到新的本机加密中,该加密将随 Rails 7.0 一起提供(目前 Rails 的稳定版本是6.1.4 和 Rails 7.0.alpha 在 GitHub 的主分支上)
代码
应用程序/模型/journal_entry.rb
class JournalEntry < ApplicationRecord
belongs_to :prayer_journal
encrypts :content
validates :content, presence: true
end
Run Code Online (Sandbox Code Playgroud)
数据库/模式.rb
create_table "journal_entries", force: :cascade do |t|
t.bigint "prayer_journal_id", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.text "content_ciphertext"
t.index ["prayer_journal_id"], name: "index_journal_entries_on_prayer_journal_id"
end
Run Code Online (Sandbox Code Playgroud)
第一个日志条目的控制台输出
#<JournalEntry:0x00007f95364745c8 …Run Code Online (Sandbox Code Playgroud)