cloedu87

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

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

zachdaniel

Creator of Ash

wonderful, thank you :slight_smile: I’ve merged your PR.

Last Post!

zachdaniel

zachdaniel

Creator of Ash

wonderful, thank you :slight_smile: I’ve merged your PR.

Where Next?

Popular in Questions Top

New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54006 488
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31494 112
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement