-
Notifications
You must be signed in to change notification settings - Fork 92
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
Dump fields using Ecto when serializing changes #83
Conversation
Hi @rschef, I'll review this PR soon. Thanks for submitting it! |
@@ -978,11 +993,6 @@ defmodule PaperTrailTest.SimpleModeBangFunctions do | |||
first(Person, :id) |> MultiTenant.add_prefix_to_query() |> repo().one() | |||
end | |||
|
|||
defp serialize(model) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This made me like the PaperTrail.Serializer
module even more, thank you. I'll read up on Ecto.embedded_dump
@@ -1,3 +1,32 @@ | |||
|
|||
defmodule LocationType do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also very interesting, thanks for adding it to the tests.
I'll read up on |
def add_prefix(changeset, prefix), do: Ecto.put_meta(changeset, prefix: prefix) | ||
|
||
def get_item_type(%Ecto.Changeset{data: data}), do: get_item_type(data) | ||
def get_item_type(%schema{}), do: schema |> Module.split() |> List.last() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interesting trying this out now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok verified that behavior is exactly the same and all tests passing
@rschef all looks good to me thank you. I have one final request, since now serializer methods are public could you also add the doc strings/documentation to those as well? Then we can merge and release it the same day, thanks! |
Hi @izelnakri, thanks for the feedback and taking the time to review this PR. Unfortunately I'm short on time this week, so I'll only be able to address your request over the weekend. |
Hi @rschef, I see more feature requests coming up. Could you finalize the PR sometime these days? Then we can merge can cut a release, thanks! |
@izelnakri Sorry for only replying to you now, these have been busy weeks. Yes, I plan to submit other 3 feature requests after this one is merged: But back to this PR, I found troublesome having to define a With that, I solved that issue, but created another one. Some Ecto types, such as Ecto.UUID, convert from string to binary when dumping a field and, therefore, Jason failed to encode it to json. So my solution was to add a configuration that allowed to skip some Ecto.Types, which was implemented here. If you agree with those decisions and solutions, I can work on this PR to implement them. Otherwise, if you have other suggestions for those issues, please let me know. |
Hi @rschef I just saw your response, sorry for replying late! This PR is pretty much done, I would just need documentation on the public methods. Please let me know when thats done, then we can merge it. Also I checked the links you've shared, seems like they have been merged to nash fork already. I think it would be better for everyone if we keep one version of |
Hi @izelnakri, thanks for your reply. Sure, I agree with you about having only one version of I'll add the missing documentation as soon as I have some time and then I can open a new PR later to implement the changes I mentioned here |
Added type specs and docs to Serializer, @izelnakri please take one more look |
Dumps changes using Ecto fields | ||
""" | ||
@spec serialize_changes(Ecto.Changeset.t()) :: map() | ||
def serialize_changes(%Ecto.Changeset{data: %schema{}, changes: changes}) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rschef what was the reason of having this public method instead of just having serialize()? Was there a performance issue previously?
Hi @rschef, thanks for adding the documentation! I have only one question and a minor documentation suggestion. Then we can merge it! |
Hi @rschef, could you rebase from master? There were few MRs merged prior, we'll need to rebase and adjust these changes. Thanks |
a06c813
to
675d502
Compare
88dc238
to
5ed018e
Compare
Hi @izelnakri, I've rebased from master :) |
* Add .tool-versions to .gitignore * Change logger level to warn in test environment * Fix warning when running tests * Create serializer module and reuse it across the application * Dump ecto fields when serializing changes * Add type specs and docs to Serializer * Replace get_sequence_from_model/1 by get_sequence_id/1 * Apply documentation
Ecto.embedded_dump/2 is now called when serializing changes, which means custom Ecto fields have their dump/1 callback called if their callback embed_as/1 return
:dump
(default is:self
).These changes were done only in this commit: nash-io@1c97a58
Fixed
test/paper_trail/base_tests.exs
file not being run, because it didn't end with the sufix_test.exs
Created
PaperTrail.Serializer
module and reused it across the applicationThe following functions were being declared in multiple modules, although they had the same implementation.
Now all modules delegate to the
PaperTrail.Serializer
module: