cloedu87
Using ash-paper-trail together with AshUUID prefixed pk's
Hi There,
On the mission to find a ash friendly way to add versioning to my project. I found ash-paper-trail.
My requirements were:
- postgres compatible
- no additional database extensions
- testing friendly (no workaround to run tests)
- support to add versioning to single resources instead of all tables
- option to only store the attributes which changed
after browsing a bit through the forum I found this post which gave me a great idea of whats possible and I started using ash-paper-trail because it ticks all the boxes.
After setting up things and migrating the database, I faced errors while executing my tests:
** (Ash.Error.Invalid) Input Invalid
* Invalid value provided for version_source_id: got invalid prefixed term.
"rec_02vbruyKluKnzDyCkFExo8"
code: assert {:ok, %Record{} = _record} = Record.create(attrs)
stacktrace:
(ash 2.18.2) lib/ash/api/api.ex:2711: Ash.Api.unwrap_or_raise!/3
(ash_paper_trail 0.1.0) lib/resource/changes/create_new_version.ex:93: AshPaperTrail.Resource.Changes.CreateNewVersion.build_notifications/2
(ash_paper_trail 0.1.0) lib/resource/changes/create_new_version.ex:22: anonymous fn/2 in AshPaperTrail.Resource.Changes.CreateNewVersion.create_new_version/1
...
then I checked my resource definition:
...
use Ash.Resource,
data_layer: AshPostgres.DataLayer,
extensions: [
AshUUID,
AshPaperTrail.Resource
]
...
attributes do
uuid_attribute :id, prefix: "rec"
attribute :name, :string
attribute :description, :string
timestamps private?: false, writable?: false
end
paper_trail do
change_tracking_mode :changes_only
store_action_name? true
ignore_attributes [:inserted_at, :updated_at]
end
...
And I was wondering if the use of AshUUID and the prefixed primary key definition leads to the fact that I can’t use ash-paper-trail at all or if I missed the one hint to make it work in this case?
It would be really a shame if it would not work, because it’s such a smooth and nice integration compared to other solutions.
All the Best
Marked As Solved
hwuethrich
Hi @zachdaniel
I created a PR with a fix for this issue: fix: correctly carry over first primary key attribute type and constraints by hwuethrich · Pull Request #36 · ash-project/ash_paper_trail · GitHub
The reason why your change did not fix the issue was that you were using the attributes variable, which does not contain the PK in most cases:
Also Liked
zachdaniel
Last Post!
zachdaniel
Popular in Questions
Other popular topics
Latest Ash Threads
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #hex
- #security









