Support remote databases

Fixed upgrade database to support remote databases.