Improvements for Ecto
I was trying to migrate from bigint ids to TypeID I came across a few problems because I need to have TypeID working during interim steps.
- You can’t use TypeID as a standard, non primary-key field (this would fail to pick up the prefix)
schema "table" do
field :uuid, TypeID, prefix: "user", type: :binary_id
end
- You can’t set the foreign key type aside from using
@foreign_key_type TypeID
belongs_to :model, Model, type: TypeID
This pull request addresses both usages I didn’t see any Ecto tests, so I haven’t provided tests.
hi! thanks for taking the time to contribute. i'll need a moment to review this more thoroughly but i did have some immediate feedback for you:
2. You can’t set the foreign key type aside from using
@foreign_key_type TypeID
you can do this using define_field: false on the belongs_to and defining the foreign key field manually. See https://github.com/sloanelybutsurely/typeid-elixir/issues/20#issuecomment-1635829743 for a more complete example.