Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to migrate existing application from paper_trail to active_snapshot #28

Open
westonganger opened this issue Sep 1, 2022 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@westonganger
Copy link
Owner

This question was raised in another thread, #14 (comment)

Is there any guide on migrating existing application from paper_trail to this gem?

@westonganger
Copy link
Owner Author

westonganger commented Sep 1, 2022

Seems to me that this should be easy to do. Disclaimer, I just whipped this up quickly, its totally untested.

class MyRecord
  has_snapshot_children do
    ...
  end
end


MyRecord.all.each do |record|
  record.versions.each do |version|

    ### Use whatever options are applicable here
    reified_record = version.reify(
      has_many: true, 
      has_one: true, 
      belongs_to: false,
    )

    snapshot_identifier = "#{version.updated_at}"

    user = User.find(version.whodunnit) if version.whodunnit

    reified_record.create_snapshot(
      identifier: snapshot_identifier, 
      user: user,
      metadata: {
        info: "Migrated from paper_trail-association_tracking"
      }
    )

  end
end

@westonganger westonganger added documentation Improvements or additions to documentation question Further information is requested and removed question Further information is requested labels Sep 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant