如何将 paper_trail 的 whodunnit 列从字符串迁移到整数?

How to migrate paper_trail's whodunnit column from string to integer?

在使用 paper_trail 的旧版 Rails 应用程序中,whodunnit 列设置为字符串,而不是默认的 current_user.id,此列包含用户的电子邮件。这是通过覆盖 ApplicationController:

中的 user_for_paper_trail 来实现的
def user_for_paper_trail
  current_user.email
end

现在我想迁移到存储当前用户 ID 而不是电子邮件的默认行为。

所以我想采取的方法是这样的:

问题是 - 我找不到可以设置 whodunnit 列名称的设置,在我看来,它是硬编码的。我看到 whodunnit 方法有一个别名(称为 version_author)。

我正在使用 Papertrail 10 和 Rails 5.2。

所以我的问题 - 执行所描述的迁移的正确方法应该是什么。

.. I couldn't find a setting, which can set the name of the whodunnit column, it seems to me, that it is hard-coded.

正确,该列必须命名为 whodunnit。它是不可配置的。

否则你的迁移听起来不错。使用事务,您将不需要临时重命名该列。 (除非您使用 MySQL,它有 "weak" 个事务,即不受 DDL 保护)