-
Notifications
You must be signed in to change notification settings - Fork 903
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
Allow storing diffed changes in object_changes column #1093
Conversation
Also, FWIW HashDiff supports "Patch/Unpatch" (https://github.com/liufengyun/hashdiff#patch) which could possibly be used for reification, removing the need for an object column, which could be used to solve the problem described here: #1046. Though this would probably entail a much more holistic change in the way paper_trail works. Just a thought, definitely don't have the time to work on that one 😄 |
Hi Ashwin,
Thanks for the clear PR description, I now understand your recommended patch format. What do you think about using a plugin design? Something like this: PaperTrail.config.object_diff_adapter = PaperTrail::ObjectDiffAdapters::HashDiff.new
# lib/paper_trail/record_trail.rb
def recordable_object_changes(changes)
if PaperTrail.config.object_diff_adapter.present?
changes = PaperTrail.config.object_diff_adapter.diff(changes)
end
# ...
end We would also use the adapter in
So, the adapter interface would have at least three methods:
That way, the new adapter (and others to come) can live in separate gems. The gem should probably be named |
Hi Ashwin, Are you still working on this? Want me to keep it open? |
@jaredbeck I have updated based on your suggestions. Right now I'm not 100% sure about details within custom attribute serialization/deserialization as I have not gone too deep into load_changeset. The method already works fine if there is no custom serialization. I think this could be moved forward and people who are doing the following could use it:
What do you think? |
Hi Ashwin, thanks for the update. I see you have added a file
I think When you say "custom attribute", is that
I am OK with the
So far, it looks like you have only implemented |
Hi @jaredbeck |
Hi Ashwin, This is getting close. Have we chosen the best name for this config option? Do you like You can name your gem whatever you want, of course, but the correct spelling according to rubygems.org is
Please add to the readme:
Please add an entry to the changelog under Unreleased -> Added. |
Hi Jared, I have updated with the changes you requested. |
Hi Ashwin. Everything looks great. However, I just realized we don't have any tests. I'm sorry I didn't mention tests earlier. It should be OK to have some very simple tests. If you want to have a simple little adapter in |
I fixed the stack overflow in version_spec; closing via #1102, preserving your authorship. Thanks for your work on this! |
Based on the discussion in #1082
This allows you to store changes in the format specified by https://github.com/liufengyun/hashdiff
This is especially useful when dealing with serialized json columns in postgres.
For example, say you have a jsonb column as follows:
and it is changed to
Previously the object changes column would have been stored as follows:
With this change, it will be stored as follows:
As you can see, the keys that were not changed (i.e. in this case, age) will not appear in the object changes at all, thus increasing storage efficiency.
If you are on board with this, I can add tests and a migration path to this format.