Rewrite migration 085 for performance.

We now make only 3 queries (one of which can be quite slow, but not TOO
slow) followed by O(n) inserts, rather than... what the ORM was doing.
Whatever that might have been.