Fix `transaction` reverting for migrations
#31604

fatkodima wants to merge fatkodima:reverting-transaction into rails:master

We do not currently have an analysis of these two commits