I'm having a bunch of tables present on my database of a Ruby on Rails application and for each table, multiple stakeholders are involved in making changes. It is getting harder to know who made what change, so I have decided to add paper_trail gem and create a version of each change.
The problem is the database already contains a sizeable amount of data in each table and I don't want to remove them. Is there a way I can create an object_change
version treating the existing data as the first version and the type of event as create
.
Consider the schema of the user's table
t.citext "email"
t.string "first_name"
t.string "last_name"
t.string "mobile"
Sample record
#<User id: 1, email: "test@example.com", first_name: "Example", last_name: "User", mobile: "1234567890", created_at: "2020-05-30 11:59:32", updated_at: "2020-05-30 11:59:32">
The expected result on running User.find(1).versions.last.changeset
=> {"id"=>[nil, 1], "email"=>[nil, "test@example.com"], "first_name"=>[nil, "Example"], "last_name"=>[nil, "User"], "mobile"=>[nil, "1234567890"], "created_at"=>[nil, Sat, 30 May 2020 11:59:32 UTC +00:00], "updated_at"=>[nil, Sat, 30 May 2020 11:59:32 UTC +00:00]}