Improving robustness of some upgrade-time sql.