I'm not sure how to reproduce this, but I have some nodes which have dangling parents, i.e. the ID does not exists in nodes table.
I think if we alter the table parentage's key parent to FOREIGN KEY(parent) REFERENCES nodes (id) could solve/detect this problem, since the folders table has been removed from schema version 2.