Add upgrade database method and merge code