13 Replies
is that possible in Ecto?
if it is then the procedure for Ash would be creating an Ash type on top of the Ecto type
Definitely doable. As @kernel said you’d essentially start with a corresponding ecto type and create the underlying type yourself. Keep in mind you’ll likely need to register the type with postgrex
I'd probably just do this particular one app side, using
Ash.Type.NewType
Sure, it is: add :horarios, {:array, :week_range}, null: false, default: []
How do I register the type with postgres using Ash? I do it in a regular Phoenix/Ecto project adding a migration manually.
well, I was thinking you might need to register it with
postgrex
, but I'm not actually sure that will be necessary 🙂
As for actually creating the type, you can do mix ecto.gen.migration
as normal and define the type just like you would have with ectoOk. I'll do that. Thanks.
FWIW, do you explicitly want that to be a complex type as opposed to something like jsonb?
Right now, I'm trying to migrate a regular Phoenix/Ecto project to Ash. I've already developed several modules that use this kind of struct. Actually, the system is based on a column that is a list of :weekrange and the weekrange type is composed of 5 fields: start_dow dow, start_time time, end_dow dow, end_time time, limit_in_seconds integer. I don't wanna refactor all modules that are already tested. I wanna use Ash with the same db resources that are in production.
What's the side effect of defining (creating) migrations outside of Ash? Does Ash understand that there is a type in the db called weekrange and that there is a resource field using that type?
okay, so create an Ash.Type that essentially proxies that type in Ash, similar to the tstzrange I gave you
Ok
no issues 🙂 Ash doesn't care one way or the other
Ok. Thanks.
What storage_type do I use for the Ash.Type?
the postgres type
:week_range
probablyBingo. That worked (at least, the migration). I'll try to use the API (crud) and will keep you updated. Thanks.