I am re-implementing an application I originally wrote in Rails in Phoenix in which users can create custom fields using PostgreSQL's JSONB record type. As an example, we have the following (simplified representation) schema:
Client
- ID (int)
- Client Type ID (int)
- Name (string)
- Info (jsonb)
Client Type
- ID (int)
- Name (string)
Custom field definition
- ID (int)
- Client Type ID (int)
- Key (string)
- Label (string)
In Rails, ActiveRecord magically converts JSONB to and from a hash, which allows me to use JSONB to very easily to store a schemaless set of custom fields.
For example, each client type can define different custom field, and then when I display the information to the user, I loop through the definitions to get the keys, which I then use to get the data out of the JSONB document.
I was trying to figure out a way to accomplish this using Ecto, and it looks like I should be looking at an embedded schema (I saw some good info here), however I don't think from looking at it that I can define a custom amount of fields to this at run-time, can I?
I was just looking for some advice on this, as so far this is the only real road block I have come across that isn't solved almost immediately.
Thanks again, I appreciate it!