Fix bugs in the new db upgrade system