izelnakri / paper_trail

Track and record all the changes in your database with Ecto. Revert back to anytime in history.
https://hex.pm/packages/paper_trail
MIT License
565 stars 92 forks source link

How to use custom Ecto type for `item_id` #235

Open mayel opened 2 months ago

mayel commented 2 months ago

Hi, thanks for merging my recent PR :) It's great that we can configure the type of ID used for item_id, but an issue for us is that it doesn't seem to work for types that aren't built-in to Ecto (such as Needle.ULID from https://www.hex.pm/packages/needle_ulid). What would be a good approach to make this possible (without simply adding such libraries as an optional dependency)?

izelnakri commented 2 months ago

Hi @mayel ,

I've never come across this issue before. What kind of error do you get? Perhaps we can simulate the scenario in a test and then create a solution/PR for this edge case scenario.

mayel commented 2 months ago

Here's a basic reproduction which results in the following compilation error: https://github.com/bonfire-networks/paper_trail/tree/custom-type-repro/example

== Compilation error in file lib/version.ex ==
** (ArgumentError) unknown type Needle.ULID for field :item_id
    (ecto 3.12.3) lib/ecto/schema.ex:2491: Ecto.Schema.check_field_type!/4
    (ecto 3.12.3) lib/ecto/schema.ex:2053: Ecto.Schema.__field__/4
    lib/version.ex:18: (module)