crpb
As I understand that is the code to create the empty database and to upgrade it, but not the code that fills it.
For me to understand the main database some code would help that iterates over all messages in the main database and fill the midb with the data, as the midb is (almost) self-explaining