Fix case databse upgrade fail risk with lazy stmt prep