Open sobafuchs opened 2 years ago
It's for convenience. In unit tests, don't use the globals, use a MigrationSet.
Is this documented anywhere? Otherwise I'd be happy to create a PR for it.
Don't think so, please do!
It's just a matter of creating a set:
set := MigrationSet[}
And using that one. instead of the global methods:
set.Exec(...)
This, by the way, has the added benefit of not keeping all migrations in memory after executing. Handy if you're resource-constrained.
The
SetTable
function is problematic if you have parallel go tests that spin up a new database and run the migrations on each individual one. It fails the go race detector as well. I'm forced to use aTestMain
function to do this I guess, but what would you do if you want to set a different migration table in different parallel tests? Is there a particular reason it was chosen to make this essentially a mutable variable on the package itself as opposed to simply passing it as an option toExec
?