Improve DB-schema migration robustness.

Sometimes a migration would crash while doing database schema changes. MySQL does not support transactions for schema chances, so there is no clean way to roll back these already performed schema migrations.

This PR modifies our DB-migration base classes to so that they should be able to resume migrating in more cases after a previously failed upgrade.

This does not solve #548, but might help in recovering from a failed migration.