Fixed upgrade SQL