The data-migration portion of this should, at the least, be run in a transaction to stop things being left in a messed up state if the migration explodes for whatever reason.