Refactor for reuse and complexity reduction

Also now avoids mutation of data fixtures.
Allow any number of top-level records to be inserted
Use natural joins for INSERT of parents/children

Much more concise SQL, with no observed effect on performance.
Human-readability much improved.
Should be easier to adapt to m2m case now.