Fixed database upgrade for some cases