Ecto.Schema / Ecto.Changeset - optional, conditionally present fields

To expand a bit on what I did, and to be clear I’m not necessarily suggesting you do this (it depends on your use case), but I essentially decided to bypass Ecto for my config storage. I wrote a Config module that directly interfaces with the underlying key/value rows and then just wrote my own load/dump functions to encode whatever types I want (I think I still only have strings and bools - maybe some day I’ll need numbers, but probably not much more than that).

Throw in a function to grab multiple keys at once (to avoid round trips) and that’s about all I ended up needing for basic config functionality. And again, for my use case I really like that I can write keys individually without having to re-encode the blob. Validation is done on the way out which means I can, for example, set a default with a simple Config.get(user, :string, "key", "default") and the data is still sparse in the DB.

This is just one path you could take of course, and if you’ve already shipped something then you probably wouldn’t want to bother migrating. Just offering another perspective :slight_smile: