Move migration into a transaction; #141

This dodges a race condition where we could fail to log some goal
changes.