Hey
So I've been wanting to do something in the CMS space around Elixir and I've tried to figure out a good way for application users to define schemas. The use case being that the user can define a content type such as Post or Page. And I want them to be dynamically manageable at runtime.
Since schemas in Ecto are Modules, creating them dynamically from user input would often be a bad idea (atom exhaustion, memory usage, probably more reasons).
Currently it looks like I could basically create a DynamicSchema module and have that generate a fake struct at runtime with the right keys, based on some kind of definition.
However Ecto also relies on the schema module to provide __schema__ functions. And those never really receive the schema struct, rather they provide information set at compile time.
This backs my solution into a corner of using something like the Process dictionary to set up a reference to the definition when instantiating my dynamic schema to make these functions behave differently for different structs. Which breaks at any process boundary. But if these __schema__ functions had more context it would be possible to do this.
It is a bit far out compared to most Ecto usage, so I get if it doesn't make sense to attempt to support doing this. But I think it has potential to do some cool stuff without needing to skip Ecto schemas.
Blog post to come with a PoC library probably. Using the Process dictionary.
-Lars Wikman