Improved upgrade script generation