How to replace Ecto.Schema modifications?
So I have my custom ULID implementation. It takes UUID format as well as BASE64 url encoded and transforms it to UUID in database layer. When taking out of DB it's transformed to BASE64 again. It creates shorter URLs which is nice. With ecto I needed just 2 lines of code to have all database IDs in this format. But I don't know what's the best way to do it in ash.
Also I've modified timestamps to be utc_datetime_usec instead of naive datetime ones. It's easier to convert them to different timezones that way.
Here's the code:
All I needed to do then was to
use App.Schema
and it was done. Is there a similar way to do it in Ash? Or at least a way to add ULID in this convenient as a separate data type?
In case anyone is interested into my ULID implementation here's gist https://gist.github.com/lamp-town-guy/306694cdb510bd93894c51bb1aaf917e9 Replies
You can do
for most of it
For the default foreign key type, that is actually a global config currenlty
You'll need to write an
Ash.Type
for ULID, although other users here can likely help with that
@kernelππΏ
i.e:
Thanks @kernel but in the end I've copied UUID and changed required parts. @Zach Daniel your snippet was useful but there were few things missing. Primary key and allow nil. I have ecto and ash types defined in different files which I might merge together.
But now when I try to create new post in Phoenix example I get this error:
How do I get to more verbose error message?
I donβt see an error there. Is that all the logs you have?
Well, that's all I get when I want to create a blog post. I have nothing in the database so it should be created.
π€ are you rendering errors in your form in any way?
In your error branch of submitting the form, try inspecting the result of this:
AshPhoenix.Form.errors(form, for_path: :all)
Might shed some light on what is going onWell, I might contribute to phoenix guide because there are no error messages in the blog example. I expected it to be there. Default value is not being generated correctly.
Yeah, so since
id
isn't part of your form, and I assume there is no corresponding error tag
What some people will do is something like this:
OK I feel super dumb.
default: &App.Type.EctoULID.generate/1
was supposed to be default: &App.Type.EctoULID.generate/0
. Thanks, it's working now.