Fix database upgrade from previous version