Ash-Postgres and uuidv7

This might be an Ecto question. If I add a Postgres function uuidv7(), can Ash use it when creating new resource instances? If not, could Ash use such a function in Elixir (that would probably be faster anyway).
4 Replies
ZachDaniel
ZachDaniel3y ago
You can create a custom type and configure the migration default for the attributes in resources so it gets set in the db (although ash will always set it in application logic if it’s got a default). attribute :id, YourUUID, primary_key?: true, default: &YourUUID.generate/0
postgres do
migration_defaults id:fragment(\”uuidv7()\”)”
end
postgres do
migration_defaults id:fragment(\”uuidv7()\”)”
end
I think something along those lines
Terris
TerrisOP3y ago
Awesome! Thank you!
Terris
TerrisOP3y ago
FYI.. uuidv7 support in Elixir https://github.com/bitwalker/uniq
GitHub
GitHub - bitwalker/uniq: Provides UUID generation, parsing, and for...
Provides UUID generation, parsing, and formatting. Supports RFC 4122, and the v6 draft extension - GitHub - bitwalker/uniq: Provides UUID generation, parsing, and formatting. Supports RFC 4122, and...

Did you find this page helpful?