1

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]}
Eyeslandic
  • 14,553
  • 13
  • 41
  • 54
Aditya Tiwari
  • 204
  • 4
  • 17
  • 1
    Does this answer your question? [PaperTrail Manually create version](https://stackoverflow.com/questions/27804421/papertrail-manually-create-version) – Eyeslandic Jun 08 '20 at 07:52
  • This gave me the idea of how to proceed and then I customized it based on my needs. Thanks – Aditya Tiwari Jun 09 '20 at 11:59

0 Answers0