I'd like to propose adding data dictionary features to Ecto.
Data DictionaryFor those who may be unfamiliar with the term a data dictionary is meta data about the data in the database. For instance, given a quantity, what's a reasonable minimum? Is there an upper bound on the value? What's the source of the number? What does the number signify? Now some may say, all of this information should be in the database and they'd be correct. But there are details which business analysts (and indeed developers) may need to know which cannot be easily captured in the database. For instance, is there some government regulation regarding the privacy of this data? If so does this regulation (GDPR for example) necessitate all deletes to be hard deletes as opposed to soft deletes? As with comments in code we sometimes need to capture not just the implementation but also the intention and the design decisions.
How Would You Add The Data Dictionary Features?While this is still to be determined, I could envision some MVP types of things that I'd like to add. For example, adding a :minimum and a :maximum option on numeric and date fields feels like relatively low hanging fruit. If you don't constrain a numeric field, then it's on the developer to catch that someone is trying to enter a negative dollar amount (which may be fine but the BA and/or the business should confirm that that's permissible). Of course that can be checked via a changeset but if it's truly a database constraint it feels like the database is where it should live. Likewise on a date/time a minimum would be the earliest date/time which would be acceptable. Again, for example, I may be able to enter 1492-01-01T00:00:00 (I'm not sure that's a valid datetime--it's solely meant as an example) as a date for an invoice but that's unlikely to be correct. While that seems unlikely to happen it could if a user fat-fingers a value. Of course, the software doesn't have common sense to question such an absurd date.
I also understand that both Postgresql and SQLServer have the ability to add comments on fields and this seems to be the right place for this sort of metadata about the field to live so that others can extract/view it later. I would need to research whether or not MySQL supports field level comments and the situation with other DB's which Ecto supports as well.
Why Are You Proposing This?Given the frequency of the answers here being "Great idea! Make a PR!" some may be wondering why I'm proposing this (as opposed to simply starting to code on it). I mean I've already started on a fork of the code so I've got a notion of how to proceed. There's a strong (and good) bias toward create code and submit a PR rather than talking an idea to death.
So I'm asking because I can't find any conversation pertaining to the idea of a data dictionary on the mailing list. I don't believe for a second that I'm such an original thinker that no one else has come up with this idea before. So I wanted to propose this to see if there were some sort of "Yeah we thought about this before and we decided against it because <x> and <y>" so I don't submit a PR that ends up wasting folks' time.
Also I would love to hear some feedback on my idea and potential approaches to making it happen. I'm very inclined to put the data dictionary information which cannot be encoded as check constraint into comments associated with the fields in the table but perhaps others have heard of other ways to do this.
Any feedback anyone cares to share would be welcomed!