Partly revert "Don't use WriteDB inside a cursor loop."

While still incorrect and dangerous, the migration functions
are irrelevant for LMDB, and rewriting them doesn't solve the problem
at hand.

This partly reverts commit 84cc02982df47b3ed5ece8f013f4bff5fbafbd94.