A schema that describes its own admin
2023年1月31日
The framework running here has an idea in it worth keeping: the ORM does not read a configuration file, it reads the database.
A MySQL table comment like orm title=Klanten sort=naam, plus one comment per column, is enough to generate the list view, the form fields, the lookups and the validation. There is even a page for editing those comments through ALTER TABLE, so the schema is the single source of truth about its own presentation.
The notation in those comments is attributes without quotes, key=value key2 key3, parsed into an array where a bare key means true. The same writing style drives the tag writer, which is why markup in this codebase reads tag('a href=/logout id=logout') rather than carrying quotes around every value.
The principle underneath is the part that matters. A column already knows almost everything about how it should be displayed, edited and validated: its type, its length, whether it may be empty, what it points at. Saying that a second time in a form definition and a third time in a validator is the waste, and every one of those repetitions is a chance for the three to disagree.
Where that description belongs is a fair question. Database metadata is invisible to version control, and a description you cannot diff is a description you cannot review. Somewhere in the source, next to the model, would answer both.