Fix bug 845355: depth limit for table of contents

Migrations for this are a bit fun since we do raw SQL to make sure it runs quickly; they do the right thing for me, but a spot-check would not be amiss to confirm.