Fix bugs in migration 085 which caused OOM on large datasets.

It was trying to load all threads and all messages into memory at the
same time, and also does not seem to explicitly commit changed data.