Fix #401 Database upgrade failed when starting freeseer

Patch to change the logic for database schema upgrades as discussed in #401. I also cleaned up some of the code and simplified the actual upgrade logic.