Improve DB-schema migration robustness.

A migration should now be able to resume in some more cases after a
previously failed upgrade.