A script to identify invalid clusters in Print Holdings MongoDB #291
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
What is it? A script to identify the clusters in the Print Holdings MongoDB that are invalid. Clusters are the main organizing unit in this database. I would like to run this regularly, perhaps together with the db backup.
Why is it? An invalid cluster doesn't let you save any information on it, until you make it valid. We currently don't have good insight into this, and that could become a problem. It may in fact already be a problem and we just don't know. I'm also going to be doing stuff to the schema, which is one of the ways you can end up with invalid clusters, so that's why now.
How big is it? The diff size may look big, but when you break it down it's:
bin/cluster_validator.rb
spec/cluster_validator_spec.rb
spec/fixtures/single_cluster_invalid.json
&spec/fixtures/single_cluster_valid.json
The fixture files are identical except for a single field (
commitment.phase
). The valid file has a 1 (valid phase), the invalid 999 (invalid phase). Why is this? Well, it's hard to make existing clusters invalid by just manipulating them, because the existing validations stop you from setting invalid values. However, data that are loaded directly into the db bypass these validations. The spec file uses the cluster-file loader to get valid/invalid clusters loaded, so it can perform tests on invalid clusters.Instead of putting this in #286 (which is already large) I broke this out into its own PR.
What kind of feedback am I looking for?
Just a general look at the validator and it's spec. It's all new code, so there isn't any tangle.
Testing
The tests run fine on github but if you want to run them yourself it is:
$ bundle exec rspec spec/cluster_validator_spec.rb
$ exit
$ docker-compose down