In Foreman we constantly change the model’s code, we add / edit / delete validations and not always migrations correctly catch these changes.
Many objects will become invalid during their lifetime, and in some places we even skip validations when creating the object.
Having tool that would report all invalid records in database would be benefit for users in multiple cases:
- Health status of database records
- Pre-upgrade check
- Post-upgrade check
- …
Implementation
I have to ideas how to implement such a feature:
- Rake task
- Foreman Feature (page)
Rake task
Simple rake tasks going over all the records and printing output to console or saving it to the .json
file, so users can use it in their CI.
From the first version it should have parameter for filtering model classes, so users can specify which classes they want to check.
This would be fairly easy to do, so it could be POC for upcoming improvements. If users will use it, and like it, then we can extend the feature and make it “bigger & better” - UI, API, recurring logic and so on …
Foreman Feature (page)
New page under Monitor section, similar to the Foreman Tasks page, with a general overview and filtering of results. There would be buttons for actions like running the health check, cleaning all the results and so on.
Table with results (found invalid records) would have information about the model (class
, id
, name
), validation messages and links for editing these objects.
In the future we can extend this page and add other health checks, like disk space, RAM monitoring, CPU usage and so on …
Things to consider
- Performance on big databases
- Filtering models - We probably don’t want to check all objects.
- Foreman Tasks and Dynflow should be involved (for performance reasons)
- … and a lot of other things I didn’t think of yet
Community
What I would like to hear from community:
- Is this something that you would use? If not please tell why
- Would you rather have a Rake task or a Foreman page (with API and everything)
- Is there something to consider, some catches and stuff to handle I didn’t mention above?