migration: Add support dry-running migrations
Add a mechanism for dry-running migrations. This is done by introducing a few new types.
- A transaction which mocks the
Commit
method to be mapped toRollback
. This allows us to create a transaction which will never commit. - A dry-run partition which wraps a given partition to provide the above transaction.
Using the above types, we introduce combinedMigrationPartition
which contains the regular migration partition and a new dry-run migration partition. The dry-run migration partition uses the stubbed dry-run partition and as such, will never commit its changes.
The combinedMigrationPartition
overrides the Begin()
method to ensure that we run both the regular migration and the dry-run migration. But the dry-run migration is run via a goroutine and hence asynchronously. We also don't return the error from the dry-run migration and simply log it.
The Close()
method is also overridden to ensure all open goroutines are closed. We don't need to close the dry-run partition since both the dry-run migration partition and the regular migration partition use the same underlying storagemgr.Partition and closing it once is sufficient.
Part of #6427