Improve DB-schema migration robustness.

A migration should now be able to resume in some more cases after a
previously failed upgrade.
Merge pull request #554 from 4teamwork/deif-migration-robustness

Improve DB-schema migration robustness.