Prefixed base62 UUIDv7 primary key implementation with Ash
Hi all,
I'm trying to implement a UUIDv7 based primary key for all our Ash resources (and relationships), storing that as UUID type column on PostgreSQL and presenting that outside as a prefixed base62 string (
I'll be happy to contribute with the result of this as a code sample or better as an elixir package as soon as I get it all working properly.
What I'd like to know, maybe from @Zach Daniel, is what is the better way with Ash to add a Resource's DSL helper like
With older version of Ash and Spark I've successfully patched the Resource's DSL, but with newer version it seems that here https://github.com/ash-project/ash/blob/main/lib/ash/resource/dsl.ex#L127 on Ash side is missing the
It seems a philosophical decision on the framework side to explicitly disallow DSL patching, so I'm wondering what is the correct way to do it.
It would be great to be able to contribute to ash via an external package that will add to the Resource's DSL a simple helper like
Another question is how to know in the Ash type module definition the Ash Resource in which it is included as an attribute, in order to generate or obtain the right prefix (maybe with Resource metadata or through a new DSL specific section).
Unfortunately I think this is not possible right now so I'm trying to get around the problem by using the constraints like
And of course any advice or tip is welcome
I'm trying to implement a UUIDv7 based primary key for all our Ash resources (and relationships), storing that as UUID type column on PostgreSQL and presenting that outside as a prefixed base62 string (
0188aadc-f449-7818-8862-5eff12733f64 will be shown as acct_02tRrww6GFm4urcMhyQpAS), like what is described here for Ecto (https://danschultzer.com/posts/prefixed-base62-uuidv7-object-ids-with-ecto).I'll be happy to contribute with the result of this as a code sample or better as an elixir package as soon as I get it all working properly.
What I'd like to know, maybe from @Zach Daniel, is what is the better way with Ash to add a Resource's DSL helper like
uuid_primary_key?With older version of Ash and Spark I've successfully patched the Resource's DSL, but with newer version it seems that here https://github.com/ash-project/ash/blob/main/lib/ash/resource/dsl.ex#L127 on Ash side is missing the
patchable?: true option that's is defined here https://github.com/ash-project/spark/blob/f997db91f74e772cd19656148092f439743f9cd8/lib/spark/dsl/section.ex#L42 on Spark side.It seems a philosophical decision on the framework side to explicitly disallow DSL patching, so I'm wondering what is the correct way to do it.
It would be great to be able to contribute to ash via an external package that will add to the Resource's DSL a simple helper like
prefix_uuidv7_primary_key.Another question is how to know in the Ash type module definition the Ash Resource in which it is included as an attribute, in order to generate or obtain the right prefix (maybe with Resource metadata or through a new DSL specific section).
Unfortunately I think this is not possible right now so I'm trying to get around the problem by using the constraints like
constraints: [prefix: "acct"] because that it's the only flexible parameter I found on the Ash types.And of course any advice or tip is welcome
