ngrams children in `node stories` are not in the `ngrams` table
with child_ngrams as
(select jsonb_array_elements_text(ngrams_repo_element->'children') as term
from node_stories)
select child_ngrams.term, ngrams.terms from child_ngrams
left join ngrams on child_ngrams.term = ngrams.terms
where ngrams.terms is null
order by child_ngrams.term
The above query reports child terms from node_stories
table (they live in a JSON struct) which aren't in the ngrams
table. I had 2 such elements, you had more than 180. This is wrong. We should add a DB constraint so that whenever this is inserted, the DB should refuse: this way we can spot which place in code is making this inconsistency.