Optimized upgrade script