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:
...
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.
relationships do
belongs_to :version_source, unquote(module) do
destination_attribute(unquote(destination_attribute))
allow_nil?(false)
attribute_writable?(true)
source_attribute(:version_source_id) # your change...
end
… shouldn’t there be a attribute_type(first_pkey_attr_type) within the belongs_to definition to use the correct type for the related resource as well ?
unless unquote(is_nil(first_pkey_attr)) do
attribute :version_source_id, unquote(Macro.escape(first_pkey_attr_type)) do
constraints unquote(Macro.escape(first_pkey_attr_constraints))
allow_nil? false
end
end
@rgraff may have an idea. As far as I can tell, the problem centers around incorrect constraints for that attribute. However, it could also be something that uuid_attribute is doing strange, I’m not familiar with the inner workings of it.
yes it’s exactly the same stack trace. but I can try searching in the direction of uuid_attribute’s behavior, maybe I can find out something in this corner…