Fix checking empty foreach in upgrade script