I implemented Mikkel's suggestion of setting the version to -1 just before an upgrade, and back to it's correct value afterwards. This is only useful if an upgrade is killed: the upgrade can also fail due to a raised OperationalError. If that is the case (regardless of whether or not the corruption comes from a bad database creation), we allow the code to fall through the statements in create_db, which safely restores the database.
Things have changed slightly:
I implemented Mikkel's suggestion of setting the version to -1 just before an upgrade, and back to it's correct value afterwards. This is only useful if an upgrade is killed: the upgrade can also fail due to a raised OperationalError. If that is the case (regardless of whether or not the corruption comes from a bad database creation), we allow the code to fall through the statements in create_db, which safely restores the database.